{"id":357,"date":"2023-02-25T08:07:22","date_gmt":"2023-02-25T00:07:22","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=357"},"modified":"2023-04-30T14:44:41","modified_gmt":"2023-04-30T06:44:41","slug":"android-get-audio-focus","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/android-get-audio-focus\/","title":{"rendered":"Android\u83b7\u53d6\u97f3\u9891\u7126\u70b9"},"content":{"rendered":"<pre><code class=\"language-java\">\/**\n * \u593a\u53d6\u6216\u91ca\u653e\u97f3\u9891\u7126\u70b9\n * @param audioManager\n * @param bMute\n *\/\nprivate void muteAudioFocus(AudioManager audioManager, boolean bMute) {\n    if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.FROYO) {\n        RLog.d(&quot;AudioRecordManager&quot;, &quot;muteAudioFocus Android 2.1 and below can not stop music&quot;);\n    } else {\n        if (bMute) {\n            audioManager.requestAudioFocus(this.mAfChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);\n        } else {\n            audioManager.abandonAudioFocus(this.mAfChangeListener);\n            this.mAfChangeListener = null;\n        }\n    }\n}<\/code><\/pre>\n<p><!-- more --><\/p>\n<ul>\n<li><code>AudioManager.AUDIOFOCUS_GAIN<\/code><\/li>\n<\/ul>\n<p>\u83b7\u53d6\u540e\u4e0drelease\uff0c\u9700\u8981\u624b\u52a8release<\/p>\n<ul>\n<li><code>AudioManager.AUDIOFOCUS_GAIN_TRANSIENT<\/code><\/li>\n<\/ul>\n<p>\u4e34\u65f6\u83b7\u53d6\uff0c\u4f7f\u7528\u540erelease<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/** * \u593a\u53d6\u6216\u91ca\u653e\u97f3\u9891\u7126\u70b9 * @param audioManager * @param bMute *\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-android-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=357"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}