我已經在我的iPhone應用中實現了AVAudioPlayer,但播放的音頻太響了。爲了使聲音稍微變平,我將音量改爲0.2f,看看它是否會起作用。音量保持完全一樣。以下是我正在使用的代碼:AVAudioPlayer太響了
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Blip.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer setVolume:0.2f];
if (audioPlayer == nil)
NSLog(@"Whoopsies, there was an error with the sound!");
else
[audioPlayer play];
爲什麼這不會降低音量?
有人可以解釋我可以嗎?
謝謝!
我很確定這兩行代碼做同樣的事情。 – gregheo 2012-03-01 04:43:53
是最初嘗試過,但沒有工作:( – 2012-03-01 19:39:24
試試這個嘗試只是用這個替換你的,也許它與NSURL上的用法有關,而不是NSString \t NSString * name = [[NSString alloc] initWithFormat: @ 「光點」]; \t的NSString *源= [[一個NSBundle mainBundle] pathForResource:名稱ofType:@ 「MP3」]; \t如果(audioPlayer){ \t \t [audioPlayer停止]; \t \t audioPlayer =零; \t} \t audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fil eURLWithPath:source] error:NULL]; \t audioPlayer.delegate = self; \t audioPlayer.volume = 0.2; \t [audioPlayer play]; – 2012-03-01 20:01:53