【发布时间】:2012-05-16 17:15:02
【问题描述】:
我似乎无法使用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);
【问题讨论】:
-
检查声音文件是否实际包含在您的应用程序包中,并且它们的文件名拼写正确(包括大小写)。
-
声音复制到我的资源文件夹,拼写正确;不幸的是,这不是问题。如果有任何帮助,我的 nslog 正在打印 0
-
我还应该提到我可以使用
AudioServicesPlaySystemSound(soundId);很好地播放声音,但我想使用AVQueuePlayer。我的 .h 文件中是否可能缺少某些内容?
标签: iphone ios ipad audio avqueueplayer