I am developing an audio streaming app for android devices and I have some issues about the handling of background audio service.
The expected behaviour of my app is that the audio source will be played continuously, even if the device is in stand-by mode with the screen off, but sometimes the background audio service is interrupted without any apparent reason.
To fix this problem, I have started the service with the option START_STICKY.
In this way, the service will be restarted even if it is closed for any reason, but now I can't close the service with a force close of the app and sometimes the service it will be restarted even if I want to close it!
Does anyone can suggest me a correct way to handle this job?
Here is my code:
At first I have declared the intent in the MainActivity:
Intent playbackServiceIntent;
Inside the onCreate() method of the MainActivity I have registered the service:
playbackServiceIntent = new Intent(this, BackgroundAudioService.class);
To start the audio service through the play button:
startService(playbackServiceIntent);
To stop the service through the stop button
stopService(playbackServiceIntent);
I have alse overrided the onDestroy() method of the MainActivity:
#Override
public void onDestroy() {
stopService(playbackServiceIntent);
//stopService(new Intent(this,BackgroundAudioService.class));
super.onDestroy();
}
Finally, the BackgroundAudioService class is defined as follow:
public class BackgroundAudioService extends Service implements OnCompletionListener {
public MediaPlayer mediaPlayer;
public WifiLock wifiLock;
PhoneStateListener mPhoneStateListener;
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
mediaPlayer = new MediaPlayer(); // raw/s.mp3
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(url);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE))
.createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock");
wifiLock.acquire();
mediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer mp, int percent) {
}
});
mPhoneStateListener = new PhoneStateListener()
{
protected boolean mWasPlayingWhenCalled = false;
#Override
public void onCallStateChanged(int state, String incomingNumber)
{
if( state == TelephonyManager.CALL_STATE_RINGING )
{ // Incoming call: Pause music
mediaPlayer.pause();
mWasPlayingWhenCalled = true;
}
else if(state == TelephonyManager.CALL_STATE_IDLE )
{ // Not in call: Play music
if( mWasPlayingWhenCalled )
{
mediaPlayer.start();
mWasPlayingWhenCalled = false;
}
}
else if( state == TelephonyManager.CALL_STATE_OFFHOOK )
{ // A call is dialing, active or on hold
mediaPlayer.pause();
mWasPlayingWhenCalled = true;
}
super.onCallStateChanged(state, incomingNumber);
}
};
TelephonyManager mgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
mgr.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (!mediaPlayer.isPlaying()) {
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
Intent intent = new Intent();
intent.setAction("com.my_app.CUSTOM_INTENT");
sendBroadcast(intent);
}
});
Time t=new Time();
t.setToNow();
}
return START_STICKY;
}
public void onDestroy() {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
}
wifiLock.release();
mediaPlayer.release();
TelephonyManager mgr1 = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if(mgr1 != null) {
mgr1.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
}
Time t=new Time();
t.setToNow();
}
public void onCompletion(MediaPlayer _mediaPlayer) {
stopSelf();
Time t=new Time();
t.setToNow();
}
}
Related
I use media player in service and activity with a button(play/stop stream).
I'm trying to do such a one thing:
start serice only once when activity starts, and than use UI part to operate with media player in service (start, stop streaming). I'm using for it Service Binder.
But when i click on button to start media player, it causes errors:
E/MediaPlayer: start called in state 1
E/MediaPlayer: error (-38, 0)
Than i added the flag isPrepared to onPrepared() and on play stream button click check the flag. Flag is always false.
It seems that onPrepare() is not called or smth like that. Why? What's wrong?
UPDATED
Activity:
public class MainActivity extends AppCompatActivity {
String url = "http://62.80.190.246:8000/ProstoRadiO128";
Button mPlayPauseButton;
boolean musicPlaying = false;
Intent serviceIntent;
MyService mService;
boolean mBound = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
initListeners();
}
#Override
protected void onStart() {
super.onStart();
serviceIntent = new Intent(this, MyService.class);
serviceIntent.putExtra("url", url);
bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
startService(serviceIntent);
musicPlaying = true;
mPlayPauseButton.setBackgroundResource(R.drawable.pause);
Log.d("", "mConnection: " + mConnection);
}
#Override
protected void onStop() {
super.onStop();
if (mBound) {
unbindService(mConnection);
mBound = false;
}
}
private ServiceConnection mConnection = new ServiceConnection() {
#Override
public void onServiceConnected(ComponentName name, IBinder service) {
MyService.MyServiceBinder binder = (MyService.MyServiceBinder) service;
mService = binder.getService();
mBound = true;
Log.d("", "in onServiceConnected: mBound = " + mBound);
}
#Override
public void onServiceDisconnected(ComponentName name) {
mBound = false;
}
};
private void initViews() {
mPlayPauseButton = (Button) findViewById(R.id.btn_play_pause);
mPlayPauseButton.setBackgroundResource(R.drawable.play);
}
private void initListeners() {
mPlayPauseButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
playPauseClick();
}
});
}
private void playPauseClick() {
if (musicPlaying == false) { //mBound &&
Log.d("", "mBound: " + mBound);
mService.startStream();
mPlayPauseButton.setBackgroundResource(R.drawable.pause);
musicPlaying = true;
}
else if (musicPlaying == true) { //!mBound
mService.stopStream();
mPlayPauseButton.setBackgroundResource(R.drawable.play);
musicPlaying = false;
}
}
}
UPDATED
Service:
public class MyService extends Service implements MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener{
String TAG = "PlayerService__Log";
String url;
MediaPlayer mediaPlayer;
private final IBinder mBinder = new MyServiceBinder();
boolean isPrepared;
public class MyServiceBinder extends Binder {
MyService getService() {
return MyService.this;
}
}
#Override
public IBinder onBind(Intent intent) {
return mBinder;
}
#Override
public void onCreate() {
Log.v(TAG, "Creating Service");
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setOnCompletionListener(this);
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand");
url = intent.getStringExtra("url");
Log.d(TAG, "url: " + url);
if (!mediaPlayer.isPlaying()) {
try {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, e.getClass().getName() + " " + e.getMessage());
}
}
return START_STICKY;
}
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
Log.d(TAG, "media player prepared");
isPrepared = true;
}
#Override
public void onCompletion(MediaPlayer mp) {
Log.d(TAG, "onCompletion");
}
#Override
public void onDestroy() {
super.onDestroy();
if (mediaPlayer != null) {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
}
mediaPlayer.release();
mediaPlayer = null;
}
}
public void startStream() {
if (!mediaPlayer.isPlaying() ) { //&& isPrepared == true
mediaPlayer.start();
Log.d(TAG, "media player started");
}
else {
Log.d(TAG, "media player is not prepared");
//isPrepared = false;
}
}
public void stopStream() {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
Log.d(TAG, "media player stoped");
}
}
}
You forgot to start the service. Call:
startService(serviceIntent);
Please read this as you will need to stop the service too.
and for pausing, rather than stop, call:
mediaPlayer.pause();
Familiarise yourself with the state diagram and invalid states in the docs.
onPrepared() is called when the player is successfully prepared/initialised.
But as the Error is indicating, something goes wrong during this phase and (probably) therfore onPrepared never gets called.
You could try to override onError, to get notified like this:
#Override
public boolean onError(MediaPlayer mediaPlayer, int what, int why) {
Log.e(TAG, "onError");
setPlayerState(PlayerState.ERROR);
if (MediaPlayer.MEDIA_ERROR_UNKNOWN == what) {
Log.d(TAG, "MEDIA_ERROR_UNKNOWN");
if (MediaPlayer.MEDIA_ERROR_IO == why) {
Log.e(TAG, "MEDIA_ERROR_IO");
if (this.playbackPosition > 0) { //we could play this video in the past, but cannot resume. start all over again.
Log.e(TAG, "Probably we requested a content range, but server didn't support that. (responded with 200), restarting!");
this.playbackPosition = 0;
start(this.playbackPosition);
} else {
callbacks.onUnrecoverableError(what, why);
}
}
if (MediaPlayer.MEDIA_ERROR_MALFORMED == why) {
Log.e(TAG, "MEDIA_ERROR_MALFORMED");
callbacks.onUnrecoverableError(what, why);
}
if (MediaPlayer.MEDIA_ERROR_UNSUPPORTED == why) {
Log.e(TAG, "MEDIA_ERROR_UNSUPPORTED");
callbacks.onUnrecoverableError(what, why);
}
if (MediaPlayer.MEDIA_ERROR_TIMED_OUT == why) {
Log.e(TAG, "MEDIA_ERROR_TIMED_OUT");
callbacks.onUnrecoverableError(what, why);
}
} else if (MediaPlayer.MEDIA_ERROR_SERVER_DIED == what) {
Log.e(TAG, "MEDIA_ERROR_SERVER_DIED");
callbacks.onUnrecoverableError(what, why);
}
return true;
}
In my app, I am using media player in service for playing a music file. I have used TelephonyManager in order to check for incoming and outgoing calls and playing and pausing music accordingly.
For incoming and outgoing calls, the app works fine and music pauses whenever a call takes place and resumes after the call disconnects. But when I try to pause manually after a call disconnects, it doesn't pause.
Below is my code:
public class ChalisaService extends Service
{
static MediaPlayer mediaPlayer;
static int playerFlag = 0;
TelephonyManager tm;
ActivityManager actManager;
Context mContext = getApplicationContext();
/**
* 0 for stop
* 1 for play
* 2 for pause*/
#Override
public IBinder onBind(Intent intent)
{
return null;
}//onBind
#Override
public void onCreate()
{
super.onCreate();
mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.chalisa);
mediaPlayer.setVolume(100, 100);
tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}//onCreate
#Override
public int onStartCommand(Intent intent, int flags, int startId)
{
if(mediaPlayer.isPlaying())
{
mediaPlayer.pause();
/*HanuAlarm.txtPlay.setText("Play");
HanuAlarm.btn_Play.setBackgroundResource(R.drawable.btnplay);*/
playerFlag = 2;
}//if
else
{
mediaPlayer.start();
/*HanuAlarm.txtPlay.setText("Pause");
HanuAlarm.btn_Play.setBackgroundResource(R.drawable.btnpause);*/
playerFlag = 1;
}//else
startForeground(0, null);
return playerFlag;
}//onStartCommand
#Override
public void onDestroy()
{
mediaPlayer.stop();
mediaPlayer.release();
playerFlag = 0;
}//onDestroy
private PhoneStateListener mPhoneListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
mContext.sendBroadcast(i);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Intent in = new Intent("com.android.music.musicservicecommand");
in.putExtra("command", "pause");
mContext.sendBroadcast(in);
break;
case TelephonyManager.CALL_STATE_IDLE:
if(!mediaPlayer.isPlaying())
{
mediaPlayer.start();
playerFlag = 1;
}//if
else
{
Intent in1 = new Intent("com.android.music.musicservicecommand");
in1.putExtra("command", "pause");
mContext.sendBroadcast(in1);
}//else
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
default:
Log.d("Chalisa Service", "Unknown phone state=" + state);
}
}
};
}//ChalisaService
Button code on which I am playing or pausing media player:
btn_Play.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(ChalisaService.playerFlag == 0 || ChalisaService.playerFlag == 2)
{
startService(in);
ChalisaService.playerFlag = 1;
Log.i("HanuAlarm play button if", ""+chalisaPlaying);
txtPlay.setText("Pause");
txtPlay.setTextColor(getResources().getColor(R.color.redwine));
btn_Play.setBackgroundResource(R.drawable.btnpause);
}//if
else if(ChalisaService.playerFlag == 1)
{
ChalisaService.mediaPlayer.pause();
ChalisaService.playerFlag = 2;
Log.i("HanuAlarm play button else", ""+chalisaPlaying);
txtPlay.setText("Play");
txtPlay.setTextColor(getResources().getColor(R.color.white));
btn_Play.setBackgroundResource(R.drawable.btnplay_a);
}//else if
}//onClick
});
I have solved my problem. Below, I am posting code for my music service.
public class ChalisaService extends Service implements OnCompletionListener
{
static MediaPlayer mediaPlayer;
static int playerFlag = 0;
TelephonyManager tm;
ActivityManager actManager;
/**
* 0 for stop/pause
* 1 for play*/
#Override
public IBinder onBind(Intent intent)
{
return null;
}//onBind
#Override
public void onCreate()
{
super.onCreate();
mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.chalisa);
mediaPlayer.setVolume(100, 100);
mediaPlayer.setOnCompletionListener(this);
tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}//onCreate
#Override
public int onStartCommand(Intent intent, int flags, int startId)
{
if(mediaPlayer.isPlaying())
{
mediaPlayer.pause();
/*HanuAlarm.txtPlay.setText("Play");
HanuAlarm.btn_Play.setBackgroundResource(R.drawable.btnplay);*/
playerFlag = 0;
}//if
else
{
mediaPlayer.start();
/*HanuAlarm.txtPlay.setText("Pause");
HanuAlarm.btn_Play.setBackgroundResource(R.drawable.btnpause);*/
playerFlag = 1;
}//else
startForeground(0, null);
return playerFlag;
}//onStartCommand
#Override
public void onDestroy()
{
super.onDestroy();
/*//mediaPlayer.stop();
//mediaPlayer.release();
playerFlag = 0;
Log.v("Chalisa service", "on destroy called");*/
}//onDestroy
private PhoneStateListener mPhoneListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
if(mediaPlayer.isPlaying())
{
mediaPlayer.pause();
playerFlag = 0;
}//if
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if(mediaPlayer.isPlaying())
{
mediaPlayer.pause();
playerFlag = 0;
}//if
break;
/**
* Nitish
* 26 Sep 2012, Wed
* 11:50 AM*/
case TelephonyManager.CALL_STATE_IDLE:
if(!mediaPlayer.isPlaying())
{
mediaPlayer.start();
playerFlag = 1;
}//if
default:
Log.d("Chalisa Service", "Unknown phone state=" + state);
}
}
};
public void onCompletion(MediaPlayer mp)
{
mp.stop();
mp.release();
playerFlag = 0;
stopSelf();
updateUI();
Log.v("Chalisa Service media player", "on completion listener called");
}
private void updateUI()
{
Intent in = new Intent("com.dzo.HanumanChalisaWithAudioAndAlarm.UPDATE_UI");
in.putExtra("Player_FLAG_VALUE", playerFlag);
getApplicationContext().sendBroadcast(in);
}
}//ChalisaService
Try to force it pausing using:
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
mContext.sendBroadcast(i);
In my app, I am using media player in service for playing a music file. It is working but eventually gets started itself after sometime, and music starts playing. I am not getting where is the problem. Below, I am posting my code:
Media Player Service
public class ChalisaService extends Service implements OnCompletionListener
{
static MediaPlayer mediaPlayer;
static int playerFlag = 0;
TelephonyManager tm;
ActivityManager actManager;
/**
* 0 for stop/pause
* 1 for play*/
#Override
public IBinder onBind(Intent intent)
{
return null;
}//onBind
#Override
public void onCreate()
{
super.onCreate();
mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.chalisa);
mediaPlayer.setVolume(100, 100);
mediaPlayer.setOnCompletionListener(this);
tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}//onCreate
#Override
public int onStartCommand(Intent intent, int flags, int startId)
{
if(mediaPlayer.isPlaying())
{
mediaPlayer.pause();
/*HanuAlarm.txtPlay.setText("Play");
HanuAlarm.btn_Play.setBackgroundResource(R.drawable.btnplay);*/
playerFlag = 0;
}//if
else
{
mediaPlayer.start();
/*HanuAlarm.txtPlay.setText("Pause");
HanuAlarm.btn_Play.setBackgroundResource(R.drawable.btnpause);*/
playerFlag = 1;
}//else
startForeground(0, null);
return playerFlag;
}//onStartCommand
#Override
public void onDestroy()
{
super.onDestroy();
/*//mediaPlayer.stop();
//mediaPlayer.release();
playerFlag = 0;
Log.v("Chalisa service", "on destroy called");*/
}//onDestroy
private PhoneStateListener mPhoneListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
if(mediaPlayer.isPlaying())
{
mediaPlayer.pause();
playerFlag = 0;
}//if
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if(mediaPlayer.isPlaying())
{
mediaPlayer.pause();
playerFlag = 0;
}//if
break;
/**
* Nitish
* 26 Sep 2012, Wed
* 11:50 AM*/
case TelephonyManager.CALL_STATE_IDLE:
if(!mediaPlayer.isPlaying())
{
mediaPlayer.start();
playerFlag = 1;
}//if
default:
Log.d("Chalisa Service", "Unknown phone state=" + state);
}
}
};
public void onCompletion(MediaPlayer mp)
{
mp.stop();
mp.release();
playerFlag = 0;
stopSelf();
updateUI();
Log.v("Chalisa Service media player", "on completion listener called");
}
private void updateUI()
{
Intent in = new Intent("com.dzo.HanumanChalisaWithAudioAndAlarm.UPDATE_UI");
in.putExtra("Player_FLAG_VALUE", playerFlag);
getApplicationContext().sendBroadcast(in);
}
}//ChalisaService
I have a class which calls this service class to play the media player
class MusicService extends Service implements OnCompletionListener {
MediaPlayer mediaPlayer;
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
mediaPlayer = MediaPlayer.create(this, R.raw.s);// raw/s.mp3
mediaPlayer.setOnCompletionListener(this);
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
}
return START_STICKY;
}
public void onDestroy() {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
}
mediaPlayer.release();
}
public void onCompletion(MediaPlayer _mediaPlayer) {
stopSelf();
}
}
I don't want it to load the raw file i want it to load a path which a string in the class that calls this service.
String path = "path is here"
private void playAudio(String url) throws Exception{
Intent music = new Intent(this,MusicService.class);
intent.putExtra("paths",path)
startService(music);
How would i go about doing this...
The music file comes from the sd card
Simply use this---------
MediaPlayer md=new MediaPlayer();
md.prepare();
md.setDataSource(path);
I don't know what are you doing in your activity but, If your are just passing a music file path in service and then want to start media player in service then I think you have to try something like this,
MediaPlayer mediaPlayer;
String musicFile;
#Override
public void onCreate() {
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnCompletionListener(this);
}
#Override
onStartCommand(Intent intent, int flags, int startId) {
musicFile=intent.getExtra("paths");
try {
mediaPlayer.reset();
mediaPlayer.setDataSource(musicFile);
mediaPlayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!mediaPlayer.isPlaying())
{
mediaPlayer.start();
}
return START_STICKY;
}
I am trying to put background music in my app.I have created an intent service which creates a Media Player and starts the music.
Once my app is launched the music is played only for a second and after that I see the following warning in my logcat:-
09-13 20:12:54.082: WARN/TimedEventQueue(33): Event 4 was not found in the queue, already cancelled?
For every run of my App, the Event number changes.This time it was Event 5.
Here is my service class which implements media player:-
import android.app.IntentService;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.widget.Toast;
public class MusicService extends IntentService {
MediaPlayer mPlayer;
private OnErrorListener mErrorListener;
public MusicService() {
super("MusicService");
// TODO Auto-generated constructor stub
}
#Override
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
// Normally we would do some work here, like download a file.
}
///////////////////////////////////////////////////////////
#Override
public int onStartCommand (Intent intent, int flags, int startId)
{
Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
mPlayer.setLooping(true);
mPlayer.start();
return super.onStartCommand(intent,flags,startId);
}
#Override
public void onCreate ()
{
super.onCreate();
// try{
mPlayer = MediaPlayer.create(this, R.raw.jingle);
//}catch (IllegalArgumentException e) {
//e.printStackTrace();
//}catch (IllegalStateException e ) {
//e.printStackTrace();
//}
if(mPlayer!= null)
{
mPlayer.setLooping(true); // Set looping
mPlayer.setVolume(100,100);
}
mPlayer.setOnErrorListener(new OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method stub
onPlayError();
return true;
}
});
}
private void onPlayError() {
Toast.makeText(this, "music player failed", Toast.LENGTH_SHORT).show();
if(mPlayer != null)
{
try{
mPlayer.stop();
mPlayer.release();
}finally {
mPlayer = null;
}
}
}
#Override
public void onDestroy ()
{
super.onDestroy();
if(mPlayer != null)
{
try{
mPlayer.stop();
mPlayer.release();
}finally {
mPlayer = null;
}
}
}
}
I got the solution.The problem was that since I am using an Intent service, so after starting the service with an intent, the player started but immediately on Destroy was called where there is a code to release and stop the player.
After removing that code I could see the music playing continuously and moreover I did not see those timed queue warnings!!!