John R
John R

Reputation: 2064

How to start same audio again on stop

In my app I am creating service to play audio. When user press any button audio stop. But If user not press any button and audio file is of length 15 second after 15 second its stop. What I want is after 15 seconds its start again and its stop only when user click button.

PlayAudio-

public class PlayAudio extends Service{
private static final String LOGCAT = null;
MediaPlayer objPlayer;

public void onCreate(){
super.onCreate();
Log.d(LOGCAT, "Service Started!");
objPlayer = MediaPlayer.create(this, R.raw.test);
}

public int onStartCommand(Intent intent, int flags, int startId){
objPlayer.start();
Log.d(LOGCAT, "Media Player started!");
if(objPlayer.isLooping() != true){
Log.d(LOGCAT, "Problem in Playing Audio");
}
return 1;
}

public void onStop(){
objPlayer.stop();
objPlayer.release();
}

public void onPause(){
objPlayer.stop();
objPlayer.release();
}
public void onDestroy(){
objPlayer.stop();
objPlayer.release();
}
@Override
public IBinder onBind(Intent objIndent) {
return null;
}
}

Upvotes: 0

Views: 83

Answers (1)

Ogen
Ogen

Reputation: 6709

objPlayer.setLooping(true);

Call that before you start it.

Upvotes: 1

Related Questions