AVAudioPlayer 超过 2 个声音
AVAudioPlayer more then 2 sounds
所以我尝试按照此处提供的所有指南同时播放 AVAudioplayer + AVA、AVA + System Sound 的 2 种声音,但没有奏效。
第二声不响
所以我决定在播放 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;
}
所以在我将 objAudio 放入 h 文件并初始化后
self.objAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:path error:nil];
一切都变得理所当然。
我不知道为什么它没有那样工作。
是bug还是有什么原因。
如果有人知道原因或有理论,我欢迎。
所以我尝试按照此处提供的所有指南同时播放 AVAudioplayer + AVA、AVA + System Sound 的 2 种声音,但没有奏效。 第二声不响
所以我决定在播放 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;
}
所以在我将 objAudio 放入 h 文件并初始化后
self.objAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:path error:nil];
一切都变得理所当然。
我不知道为什么它没有那样工作。
是bug还是有什么原因。
如果有人知道原因或有理论,我欢迎。