我有一个AVQueuePlayer
设置如下的属性。声明报告音频应该可以正常播放(在NSLog
应用程序运行时),但是在模拟器和 iOS 设备本身(iPhone 5s iOS 8.1.1)上进行测试时,没有音频播放。
我已经确认该设备没有静音,并且处于全音量状态。我正在使用 Xcode 6 和 iOS 8 SDK。我在“链接二进制文件”部分导入了 AVFoundation 框架,并将其导入我的班级。
-(void)viewDidLoad
{
[super viewDidLoad];
[self music];
// other setup code
}
- (void)music
{
music = [[NSMutableArray alloc]initWithArray:@[
[AVPlayerItem playerItemWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"BM1"
ofType:@"mp3" ]]],
[AVPlayerItem playerItemWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"BM2"
ofType:@"mp3" ]]],
[AVPlayerItem playerItemWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"BM3"
ofType:@"mp3" ]]],
[AVPlayerItem playerItemWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"BM4"
ofType:@"mp3" ]]],
[AVPlayerItem playerItemWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"BM5"
ofType:@"mp3" ]]],
[AVPlayerItem playerItemWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"BM6"
ofType:@"mp3" ]]],
[AVPlayerItem playerItemWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"BM7"
ofType:@"mp3" ]]]
]];
for(AVPlayerItem *a in music)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemFinished:) name:AVPlayerItemDidPlayToEndTimeNotification object:a];
}
[music shuffle];
self.audio = [[AVQueuePlayer alloc]initWithItems:music];
[self.audio play];
NSLog(@"Now playing%@",[self.audio currentItem]);
NSLog(@"%@",self.audio);
}
-(void)playerItemFinished:(NSNotification *)notification
{
if([[self.audio currentItem] isEqual:[music lastObject]])
{
self.audio = nil;
[music shuffle];
self.audio = [[AVQueuePlayer alloc]initWithItems:music];
[self.audio play];
}
}