所以我尝试了所有的指南,在这里提供了同时播放2个声音,由AVAudioplayer + AVA,AVA +系统声音,但它没有工作。第二种声音从来不听。
所以我决定在播放2.音频(铃音)之前先停止主音频,但它没有工作。
我需要同时播放2种声音,或者1.音频会暂停。(我的h文件中有委托)
下面是代码,这个方法由NSTimer每0.5秒调用一次:
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;
}发布于 2017-03-06 12:19:39
因此,在我将objAudio放到h文件并初始化之后
self.objAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:path error:nil];一切都如出一辙。
我不知道为什么不这样做。
是有问题还是有某种原因。
如果有人知道原因或者有我欢迎的理论。
https://stackoverflow.com/questions/42611363
复制相似问题