0

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

How to play audio in android

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!!!

Community
  • 1
  • 1
TheMohanAhuja
  • 1,855
  • 2
  • 19
  • 30

0 Answers0