简体   繁体   中英

MediaPlayer is stopping the sound when activity goes to background

[EDITED] My app is basically a listview that each row (position) play a sound that is playing in loop until the same position is pressed again.

I create each sound by MediaPlayer.create() and stop all of them on onDestroy() of activity (in order to if the activity is destroyed - by pressing back button for instance, all sounds be sttoped).

The problem is: this works very well (I tried for 5 hours continously) on a device with API 16. But on my other device (tablet API 22) when the home button is pressed the sound is immediately turned off, however the same does not occurred on emulator with API 22 also.

Now I'm insecure about my app. I don't know if my app is wrong, if the emulator is or if my device is. :( Anyone already had the same behavior with sounds on app? Anyone knows if has any configuration on tablet with API 22 that can produce this behavior? And mostly how I fix this?

NOTE - I don't want to use service 'cause like I said that way was working well and with service I had some problems with index of my array that store the positions already pressed.

Thanks

After so many hours struggling with this stupid question and wondering why my tablet had a behavior different of emulator, I finally found the answer, a simple answer.

My tablet was setted to don't keep activities on developer options , then when the home button was pressed the activity was destroyed and all sounds turned off. It was just uncheck this option and now everything works.

If anyone have the same problem can be this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM