Problem:
How do I check if music is already playing on an Android device from within an Activity?
Solution:
AudioManager aMan = (AudioManager)this.getSystemService(
Context.AUDIO_SERVICE);
if(aMan.isMusicActive()) {
// do stuff here if music is playing
}
Notes:
This check can be useful if your app needs to play music. This is because there are instances where attempting to play music using MediaPlayer while music is already playing will corrupt an audio stream on an Android device.
Thanks.
ReplyDeleteglad it helped @Long Tran. Thanks for the comment!
ReplyDelete