简体   繁体   中英

Mediaplayer stops after 5 seconds on new Activity

I have 2 Activities a main one which starts a mediaplayer stream, and a button leading to starts Activity #2 and then finish() the current Activity the tasks for Activity #1 are completed at this point, musicplayer gives no problem at this point. After the Activity #2 is opened however, the mediaplayer works for about 5 seconds and then it stops, in Activity #2 I only have a button to exit and an AsyncTask running in a loop with the help of a Handler.

I believe you're MediaPlayer from Activity 1 is being wiped from memory since you're calling finish() . The MediaPlayer instance is part of the first Activity . The only way to fix this is to start a new MediaPlayer in your Activity 2 or create a Service that handles all media in the background. If you do it the second way, the one MediaPlayer instance will remain playing through all your activities and you only need to send commands to it.

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