How can I play Background Sound throughout my application, even if activities keeps on changing.
I have found code for playing sound in background for one activity as:
public class BackgroundSound extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
MediaPlayer player = MediaPlayer.create(YourActivity.this, R.raw.test_cbr);
player.setLooping(true); // Set looping
player.setVolume(100,100);
player.start();
return null;
}
}
I am not getting anyway to play sound in application content not activity context.
So I think there must be some way to achieve this using singleton class or service?
Play Background Sound in android applications
I have followed above both links but it doesn't seems to help me though, its playing sound but not with my instruction from second time, first it works where ever I want to start.
Any Help would be highly appreciated!!!