Solution for automatic interruption of mediaplayer playing music in Android

Source: Internet
Author: User

Today, I tried to keep plotting in a surfaceview.ProgramIn the background music, a fault occurs:

The music stops playing in just over 10 seconds, so there will be no sound.

Try to replace it with another MP3 file.

The attempt to switch the playback operation from the subthread to the main thread still fails. The fault is the same.

Try to comment out all execution except "Super. oncreate (savedinstancestate );"CodeEven if the layout is not set, it's okay. You can play it normally, but you cannot play music on a black screen. There's another bird to use ~

Then try to set the mediaplayer from the temporary variable to the member variable of the activity. The problem is solved.

The possible cause is that the mediaplayer is a temporary variable and the result is randomly removed by the garbage collector ...... Cup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.