在iOS模拟器中无法在后台播放音频 [英] Audio playing in background not working in iOS Simulator

查看:94
本文介绍了在iOS模拟器中无法在后台播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到许多有关在后台播放音频的问题.这些问题通常会问为什么音频会在模拟器的背景中播放,而设备却根本无法播放.

I've seen lots of questions about playing audio in the background. These questions often ask why the audio plays in the background of the simulator, yet the device simply wouldn't.

就我而言,它是相反的.

In my case, it's reversed.

当我在iPad上测试示例应用程序时,它运行良好.但是,当我开始在模拟器中进行测试时,它根本不会继续在后台播放.

When I tested my sample app in my iPad, it worked perfectly. However, when I began testing in the simulator, it simply wouldn't continue playing in the background.

这是我使用的代码:

NSURL *url = [NSURL URLWithString:firstSong];

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[audioPlayer setNumberOfLoops:-1];
[audioPlayer setCurrentTime:0];

[[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance]setDelegate:self];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];

[audioPlayer play];

有人可以告诉我为什么这行不通吗?是bug还是什么?

Can anyone tell me why this won't work? Is it a bug or something?

推荐答案

iOS Simulator afaik不支持背景音频.

Background audio is not supported in iOS Simulator afaik.

这篇关于在iOS模拟器中无法在后台播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆