ios - 关闭屏幕时 AVPlayer 停止播放音乐
<p><p>我的项目相关音乐和我在关闭屏幕时停止播放音乐的问题。虽然我注册了背景模式(音频),但有时当我关闭屏幕 AVPlayer 停止播放音乐并在打开屏幕时再次播放。</p>
<p>我花了很多时间,但我知道为什么会这样。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>仅添加 <code>audio</code> 后台模式是不够的。您还必须设置播放 Audio Session 类别,如 <a href="https://developer.apple.com/library/content/qa/qa1668/_index.html" rel="noreferrer noopener nofollow">described in Apple QA1668</a> :</p>
<blockquote>
<p>A: You must declare your app plays audible content while in the background, and assign an appropriate category to your audio session.</p>
</blockquote>
<pre><code>#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
AVAudioSession *audioSession = ;
NSError *setCategoryError = nil;
BOOL success = ;
if (!success) { /* handle the error condition */ }
NSError *activationError = nil;
success = ;
if (!success) { /* handle the error condition */ }
</code></pre></p>
<p style="font-size: 20px;">关于ios - 关闭屏幕时 AVPlayer 停止播放音乐,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40083211/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40083211/
</a>
</p>
页:
[1]