我目前在我的应用程序中播放背景音乐和其他声音的方式表现得非常奇怪:
- 关闭背景音乐,播放的其他声音会更大。
- 开启背景音乐后,声音会小很多。
- 您甚至可以将音乐调到中音,声音会变得更安静。
最奇怪的部分: 当 iPhone 的音量一直被调低(静音)时,根本就没有声音。在背景音乐打开但没有设备音量的情况下,它可以满足您的预期 - 您听不到音乐或声音效果。但是如果关闭背景音乐,即使设备本身完全关闭,声音效果仍然会播放并且声音很大!
这是我的代码...
对于我的背景音乐:
AVAudioPlayer *musicPlayer;
- (void)playMusic {
if (musicPlayer == nil) {
NSURL *musicPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"SongFile" ofType:@"mp3"]];
musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicPath error:nil];
musicPlayer.volume = 0.2f;
musicPlayer.numberOfLoops = -1;
}
[musicPlayer play];
}
- (void)stopMusic {
[musicPlayer stop];
}
对于播放过程中的声音:
#import "SoundEffect.h"
SoundEffect *sounds;
- (void)playSoundWithInfo:(NSString *)sound; {
NSString *path = [[NSBundle mainBundle] pathForResource:sound ofType:@"caf"];
sounds = nil;
sounds = [[SoundEffect alloc] initWithContentsOfFile:path];
[sounds play];
}
任何想法将不胜感激。