[Android] Stop and resume playing back music

Source: Internet
Author: User

During the recording operation, we hope to stop the music played by codoy and other backend players and resume playing after the recording is completed. You can use the following code:

/** @ Param bmute: If the value is true, background music is disabled. * // @ Targetapi (build. version_codes.froyo) public static Boolean muteaudiofocus (context, Boolean bmute) {If (context = NULL) {log. D ("android_lab", "context is null. "); Return false;} If (! Versionutils. isrfroyo () {// versions earlier than 2.1 do not support the following APIs: requestaudiofocus and abandonaudiofocuslog. D ("android_lab", "android 2.1 and below can not stop music"); Return false;} Boolean bool = false; audiomanager AM = (audiomanager) context. getsystemservice (context. audio_service); If (bmute) {int result = aM. requestaudiofocus (null, audiomanager. stream_music, audiomanager. audiofocus_gain_transient); bool = Result = audiomanager. audiofocus_request_granted;} else {int result = aM. abandonaudiofocus (null); bool = Result = audiomanager. audiofocus_request_granted;} log. D ("android_lab", "pausemusic bmute =" + bmute + "result =" + bool); Return bool ;}

This article is sodino all, reprint please note the Source: http://blog.csdn.net/sodino/article/details/10055659
Or not? You try to follow the public account sodino, And the blog will be pushed to you in the future.

Related Article

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.