Android - Too many instances of MediaPlayer
I have an activity that has 12 buttons, and each one plays a separate file. I have created 12 di开发者_Go百科fferent MediaPlayers and set them with the correct file like this:
music = MediaPlayer.create(this, R.raw.music);
This worked fine for just a few instances, but now it says I have too many instances and the program will just crash before anything happens. I have tried just creating one MediaPlayer instance and just try to change the file the it plays when the button is pressed by using the create method like usual, but this doesn't work.
Is there a way to do this or have any ideas?
Make music as Singleton.. Reuse the same object created. this may sort out your problem.
Did you use mediaPlayer.release()
when you change files?
精彩评论