Android: How To Stop Other Active Media Players?
I'm trying to create a music player. My application has 2 players - (a) plays songs from the memory (b) plays online music streams using URLs The home/default activity of my app
Solution 1:
You can create a class in your project and call it MediaPlayerRegistry where you store a reference to each mediaPlayer object you are currently using. and access them anywhere in your app to stop / release / replay them. it would look something like this:
publicclassMediaPlayerRegistry {
publicstaticList<MediaPlayer> mList = new ArrayList<MediaPlayer>();
}
Then from any activity you have you can call:
MediaPlayerRegistry.mList.put(MediaPlayer mPlayer);
to add it to your registry... and when you want to release it stop any running object.
for ( MediaPlayer player : MediaPlayerRegistry.mList) {
if (player != null && player.isplaying() {
player.release();
}
}
just think of it as your own pool of MediaPlayer objects
Post a Comment for "Android: How To Stop Other Active Media Players?"