首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVQueuePlayer不播放声音

AVQueuePlayer不播放声音
EN

Stack Overflow用户
提问于 2012-05-16 17:15:02
回答 2查看 646关注 0票数 0

我似乎无法用AVQueuePlayer播放声音。该应用程序编译并运行良好,但当调用“`imageTouched”方法时,我不会收到任何音频。有人能帮忙吗?

代码语言:javascript
复制
-(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工作。请帮帮我!

代码语言:javascript
复制
NSString *path;
SystemSoundID soundId;
path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
NSURL *url = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID( (CFURLRef)objc_unretainedPointer( url), &soundId);
AudioServicesPlaySystemSound(soundId);
EN

回答 2

Stack Overflow用户

发布于 2012-12-10 06:20:00

我意识到现在对你来说可能已经太晚了,但我怀疑原因是AVQueuePlayer是立即自动发布的,所以没有声音播放。试一试[[AVQueuePlayer alloc] initWithItems:sounds]

票数 0
EN

Stack Overflow用户

发布于 2013-01-30 14:45:23

我做了几乎相同的思考,但是没有在函数中声明AVQueuePlayer *player,而是在interface中声明它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10623418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档