我似乎无法用AVQueuePlayer播放声音。该应用程序编译并运行良好,但当调用“`imageTouched”方法时,我不会收到任何音频。有人能帮忙吗?
-(void) imageTouched
{
NSString * path1 = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
NSString * path2 = [[NSBundle mainBundle] pathForResource:@"sound2" ofType:@"wav"];
NSURL *url1 = [NSURL fileURLWithPath:path1];
NSURL *url2 = [NSURL fileURLWithPath:path2];
AVPlayerItem *firstSound = [AVPlayerItem playerItemWithURL:url1];
AVPlayerItem *secondSound = [AVPlayerItem playerItemWithURL:url2];
NSArray *sounds = [NSArray arrayWithObjects:firstSound, secondSound, nil];
AVQueuePlayer *player = [AVQueuePlayer queuePlayerWithItems:sounds];
[player play];
NSLog(@"%d",player.status);
}编辑1:我检查过的文件名(大小写、拼写等)是否有任何问题,并且似乎没有问题。我已经能够用下面的代码播放声音,但我真的需要让AVQueuePlayer工作。请帮帮我!
NSString *path;
SystemSoundID soundId;
path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
NSURL *url = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID( (CFURLRef)objc_unretainedPointer( url), &soundId);
AudioServicesPlaySystemSound(soundId);发布于 2012-12-10 06:20:00
我意识到现在对你来说可能已经太晚了,但我怀疑原因是AVQueuePlayer是立即自动发布的,所以没有声音播放。试一试[[AVQueuePlayer alloc] initWithItems:sounds]。
发布于 2013-01-30 14:45:23
我做了几乎相同的思考,但是没有在函数中声明AVQueuePlayer *player,而是在interface中声明它。
https://stackoverflow.com/questions/10623418
复制相似问题