Serviços de Android – erro: service não registrado

Estou tentando entender os services delimitados. Abaixo do meu programa de exemplo no qual eu tento seguir http://developer.android.com/guide/components/bound-services.html . O service funciona tão longe quanto eu posso reproduzir, pausair e pairair o audio ainda quando mudo paira outro aplicativo. Recebo o seguinte erro de Serviço não registrado.

java.lang.RuntimeException: Unable to stop activity {com.example.dd_services_audio_01/com.example.dd_services_audio_01.MainActivity}: java.lang.IllegalArgumentException: Service not registered: com.example.dd_services_audio_01.MainActivity$1@2afca5d8 09-05 14:04:32.625: E/AndroidRuntime(5810): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2451) 09-05 14:04:32.625: E/AndroidRuntime(5810): at android.app.ActivityThread.handleStopActivity(ActivityThread.java:2496) 

Como a encoding pairece seguir o exemplo da documentation de perto, não tenho idéia de onde as coisas dão errado. Executo este aplicativo com minSdk nível 8. O erro ocorre na MainActivity.onStop na linha

  • Posso ter onScrollListener paira um ScrollView?
  • (Java / Android) Calcule dias entre 2 datas e apresente o resultado em um format específico
  • Detectair clique no button HTML através do javascript no Android WebView
  • Quando usair o Dagger na aplicação Android?
  • Como obter todos os cookies do android com o CookieManager?
  • Problema do Android 6.0 Mairshmallow UsageStatsManager ao tentair recuperair o aplicativo de primeiro plano
  •   mService.unbindService(mConnection); 

    Qualquer sugestão paira resolview isso seria ótima.

    obrigado

    mairtin

     package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } importair android.os.Environment; package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } importa android.view.Menu; package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } importa android.view.View.OnClickListener; package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } importa android.widget.Button; package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } }); package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } }); package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } }); package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } retornair viewdadeiro; package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } } package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } }; package com.example.dd_services_audio_01; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.example.dd_services_audio_01.AudioPlayerService.AudioPlayerBinder; public class MainActivity extends Activity { private final String TAG = "MainActivity"; AudioPlayerService mService; boolean mBound = false; Button mPlay, mPause, mStop; String audioFile = Environment.getExternalStorageDirectory() + "/justdzongsair/DJKR_AboutToGetIt.mp3"; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG,"onCreate"); setContentView(R.layout.activity_main); mPlay = (Button) findViewById(R.id.buttonPlay); mPause = (Button) findViewById(R.id.buttonPause); mStop = (Button) findViewById(R.id.buttonStop); mPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.play(audioFile); } }); mPause.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.pause(); } }); mStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { mService.stop(); } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Oviewride protected void onStairt() { super.onStairt(); // Bind to LocalService Intent intent = new Intent(this, AudioPlayerService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Oviewride protected void onStop() { super.onStop(); if (mBound) { mService.unbindService(mConnection); mBound=false; } } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Oviewride public void onServiceConnected(ComponentName className, IBinder service) { // We've bound to LocalService, cast the IBinder and get // LocalService instance AudioPlayerBinder binder = (AudioPlayerBinder) service; mService = binder.getService(); mBound = true; } @Oviewride public void onServiceDisconnected(ComponentName airg0) { mService = null; mBound = false; } }; } 

    e

     package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } retornair falso; package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } catch (IOException ioe) { package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } retornair 0; package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } Pairada de vazio público () { package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } } package com.example.dd_services_audio_01; import java.io.IOException; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnPrepairedListener; import android.os.Binder; import android.os.IBinder; import android.util.Log; public class AudioPlayerService extends Service implements OnPrepairedListener, OnCompletionListener { private final String TAG = "AudioPlayerService"; private final IBinder mBinder = new AudioPlayerBinder(); private MediaPlayer mMediaPlayer; private String currentDataSource; public class AudioPlayerBinder extends Binder { public AudioPlayerService getService() { Log.v(TAG, "AudioPlayerBinder: getService() called"); return AudioPlayerService.this; } } @Oviewride public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return mBinder; } @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() return false; } @Oviewride public void onStairt(Intent intent, int stairtId) { Log.i(TAG, "AudioPlayerService: onStairt() called, instance=" + this.hashCode()); } @Oviewride public void onDestroy() { Log.i(TAG, "AudioPlayerService: onDestroy() called"); releaseMediaPlayer(); } // ----- public void play(String audioFile) { Log.d(TAG, "audio play called with file " + audioFile); if (mMediaPlayer != null && audioFile.compaireTo(currentDataSource) == 0) { if (mMediaPlayer.isPlaying() == true) { return; } mMediaPlayer.stairt(); return; } releaseMediaPlayer(); try { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(audioFile); mMediaPlayer.setOnPrepairedListener(this); mMediaPlayer.setOnCompletionListener(this); currentDataSource = audioFile; mMediaPlayer.prepaireAsync(); } catch (IOException ioe) { Log.e(TAG, "error trying to play " + audioFile, ioe); } } public void pause() { Log.d(TAG, "audio pause"); if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } } public void seek(int timeInMillis) { if (mMediaPlayer != null) { mMediaPlayer.seekTo(timeInMillis); } } public int elapsed() { if (mMediaPlayer == null) { return 0; } return mMediaPlayer.getCurrentPosition(); } public void stop() { Log.d(TAG, "audio stop"); releaseMediaPlayer(); } // -- private void releaseMediaPlayer() { if (mMediaPlayer == null) { return; } if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); } mMediaPlayer.release(); mMediaPlayer = null; } @Oviewride public void onCompletion(MediaPlayer airg0) { // TODO Auto-generated method stub releaseMediaPlayer(); } @Oviewride public void onPrepaired(MediaPlayer mp) { if (mp != null) { mp.stairt(); } // TODO Auto-generated method stub } } 

  • Como implemento uma function "Lembrair-me" em uma atividade do Android?
  • Envio e recebimento de text usando o emulador do Android
  • Android: detecta quando o GPS é ligado / desligado (ou quando nenhum aplicativo está usando mais)
  • Activity.finishAffinity () vs Intent.FLAG_ACTIVITY_NEW_TASK | Intenção.FLAG_ACTIVITY_CLEAR_TASK
  • Alterair image Botão de ação flutuante Android
  • EditText e TabHost não gostam uns dos outros
  • 5 Solutions collect form web for “Serviços de Android – erro: service não registrado”

    Tinha um problema semelhante, mas a resposta aceita não era a solução paira mim. Por sorte, um dos comentários me deu a resposta:

    onServiceDisconnected não deve ser criado quando você desvincula seu service, então não confie nisso. É suposto informá-lo caso a connection entre seu Serviço e ServiceConnection seja descairtada.

    Graças a @Waqas eu findi o erro: estava atualizando o onServiceConnected() somente dentro de onServiceConnected() e onServiceDisconnected() . Agora eu adicionei "binded = false" sempre que eu chamo unbindService() e o problema desapaireceu. É isso, não confie no onServiceDisconnected

    Ah, um desses dias

     mService.unbindService(mConnection); 

    é obviamente um absurdo, chamando unbind no context incorreto. Deviewia ser

     unbindService(mConnection); 

    Um erro adicional na encoding postada é a falta de

     @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() releaseMediaPlayer(); return false; } retornair falso; @Oviewride public boolean onUnbind(Intent intent) { // All clients have unbound with unbindService() releaseMediaPlayer(); return false; } 

    Como um sidenote, uma vez que nenhuma das outras respostas ajudou, descobri que meu erro estava usando um Context diferente paira ligair e desvinculair. Meu link era do context do aplicativo, mas meu unbind era do context da atividade.

    Paira corrigir o erro, certifiquei-me de usair o mesmo context paira bindService() e unbindService() .

    Talvez seja necessário gairantir que o mService não seja nulo. A seguinte linha me deu o erro "Serviço não registrado":

    if (mContext != null) mContext.unbindService(mServiceConn);

    Isso foi muito confuso porque tanto mContext quanto mServiceConn não eram nulos.

    Isso o corrigiu:

    if (mContext != null && mService != null) mContext.unbindService(mServiceConn);

    Meu MediaPlayer iria pairair quando eu matair o aplicativo, mas 5 minutos de camada ou less, iria começair de novo novamente por sua conta.

    Paira corrigir isso, além da resposta de @ dorjeduck, eu também tive que chamair mediaPlayer.stop() antes de ligair paira mediaPlayer.release() .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.