Reputation: 11
package my.app.bhaktamar;
import android.app.Activity;
//import android.content.Intent;
import android.media.MediaPlayer;
//import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
//import android.view.View;
public class MainActivity extends Activity {
MediaPlayer dontcall;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.e("Pickle", "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
Log.e("pickle", "onResume");
dontcall = MediaPlayer.create(this, R.raw.gpad1);
dontcall.start();
super.onResume();
}
@Override
protected void onPause() {
Log.e("pickle", "onPause");
dontcall.stop();
dontcall.release();
super.onPause();
}
}
What should i do so sound should play after autolock ?
Upvotes: 1
Views: 68
Reputation: 847
You need to use Service to play music background. If you want to play after autolock, use WakeLock.
Upvotes: 0
Reputation: 1413
use stop mediaplayer content in ondestroy()
in your activity,so when your close activity after then the mediaplayer will stop.
@Override
public void onDestroy()
{
dontcall.stop();
dontcall.release();
super.onDestroy();
}
Upvotes: 1