【发布时间】:2011-12-18 12:20:51
【问题描述】:
我目前在我的应用中播放背景音乐和其他声音的方式非常奇怪:
- 关闭背景音乐,播放的其他声音会更大。
- 打开背景音乐后,声音会小很多。
- 您甚至可以将音乐调到中音,声音会变得更安静。
最奇怪的部分: 当 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];
}
任何想法都将不胜感激。
【问题讨论】:
-
你在更多设备上测试过这个吗?跨设备是否一致?
-
这不会发生在 iPad(第一代,iOS 5)上。这是迄今为止我能够测试的唯一其他设备。发生这种情况的 iPhone 也是 iOS 5。
-
好吧,这让你对这个问题投了赞成票。确实感觉是您的设备有问题
-
你的 AVAudioSessionCategory 设置是什么?
-
没有看到你的代码,我不知道,但尝试阅读:stackoverflow.com/questions/1659167/…
标签: iphone audio avaudioplayer soundeffect