AVAudioPlayer超过2个声音

时间:2017-03-05 17:09:22

标签: ios objective-c avaudioplayer

所以我试过这里提供的所有指南同时播放AVAudioplayer + AVA,AVA + System Sound的2个声音,但它没有用。 第二声音永远不会响起。

所以我决定在播放之前停止主音频2.音频(铃声音频) 它没用。

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

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

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;
}

1 个答案:

答案 0 :(得分:0)

所以在我将objAudio放入h文件并初始化

之后
Dim selectedDate As Date 

一切都变得应有。

我不知道为什么它没那样起作用。
它是错误还是有某种原因。
如果有人知道为什么或有一个我欢迎的理论。

相关问题