首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVAudioPlayer超过2个声音

AVAudioPlayer超过2个声音
EN

Stack Overflow用户
提问于 2017-03-05 17:09:22
回答 1查看 56关注 0票数 1

所以我尝试了所有的指南,在这里提供了同时播放2个声音,由AVAudioplayer + AVA,AVA +系统声音,但它没有工作。第二种声音从来不听。

所以我决定在播放2.音频(铃音)之前先停止主音频,但它没有工作。

我需要同时播放2种声音,或者1.音频会暂停。(我的h文件中有委托)

下面是代码,这个方法由NSTimer每0.5秒调用一次:

代码语言:javascript
复制
if(!(bellint == -0.5)){
    bellint = bellint+0.5;
}
if(!(self.loaderAudioView.fakeDuration == secondsTime)){
    secondsTime = secondsTime +0.5;
    self.loaderAudioView.fakeTimer = secondsTime ;
    NSLog(@"fakedur %f , secondsOfTimer : %f" ,self.loaderAudioView.fakeTimer,secondsTime);
}
else{
    self.loaderAudioView.fakeTimer = secondsTime = 0 ;
    [self.timer invalidate];
    self.playOrPauseButton.on = NO;
}
if((int)secondsTime % self.bellsInt == 0.0){
    [self.loaderAudioView pausePlayer];
     bellint = bellint+0.5;

    NSURL *path = [[NSBundle mainBundle] URLForResource:@"bell_start" withExtension:@"mp3"];
    // I've putted here AVAudioplayer initialization cause you can see. It's in another method realized.Here I just call [objAudio play];

    AVAudioPlayer* objAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:path error:nil];

    objAudio.delegate = self;

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive: YES error: nil];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [objAudio prepareToPlay];
    [objAudio play];

    NSLog(@"BANG");
}
if(bellint == 5.0){
    [self.loaderAudioView playPlayer];

    bellint = -0.5;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-06 12:19:39

因此,在我将objAudio放到h文件并初始化之后

代码语言:javascript
复制
self.objAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:path error:nil];

一切都如出一辙。

我不知道为什么不这样做。

是有问题还是有某种原因。

如果有人知道原因或者有我欢迎的理论。

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

https://stackoverflow.com/questions/42611363

复制
相关文章

相似问题

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