iPhone 上运行应用程序的声音太小
我编写了一个可以在 iPad 和 iPhone 上运行的应用程序。我正在使用 AVAudioPlayer 来播放声音。现在我遇到了音量级别的一些问题。
在 iPad 上运行时,一切都很好,播放声音的音量也很好,在 iPad 模拟器中运行时也是如此。
当应用程序在 iPhone 上运行时,问题就出现了:虽然 iPhone 模拟器中的音量水平很好,但设备上的音量水平非常低。
这是我在两台设备上使用的代码:
if (audioPlayerAtmo==nil)
{
NSString *filename = [NSString stringWithFormat:@"Atmo_%i", currentPage];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:filename ofType:@"mp3"]];
AVAudioPlayer *tempPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
tempPlayer.delegate = self;
//NSLog(@"tempPlayer.volume: %f", [tempPlayer volume]);
[tempPlayer setVolume:1.0f];
//NSLog(@"tempPlayer.volume: %f", [tempPlayer volume]);
self.audioPlayerAtmo = tempPlayer;
[tempPlayer release];
[audioPlayerAtmo play];
btAtmo.selected = YES;
}
else // player exists
{
// ...
}
有人知道为什么 iPhone 上的电平如此低,而模拟器和 iPad 上一切正常吗?
预先感谢您的帮助。
技术数据: 代码3.2.4 iPhone 4(版本 4.1)
I've written an App supposed to BE run both on iPad and on iPhone. I'm using AVAudioPlayer for playing back sound. Now I've run into some problems with the volume levels.
When running on the iPad, everything is fine, the volume level of the sound being played is fine, also when running in the iPad simulator.
The problem arises when the app is being run on the iPhone: whereas the volume levels in the iPhone simulator are fine, the levels on the device are very low.
Here's the code I'm using on both devices:
if (audioPlayerAtmo==nil)
{
NSString *filename = [NSString stringWithFormat:@"Atmo_%i", currentPage];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:filename ofType:@"mp3"]];
AVAudioPlayer *tempPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
tempPlayer.delegate = self;
//NSLog(@"tempPlayer.volume: %f", [tempPlayer volume]);
[tempPlayer setVolume:1.0f];
//NSLog(@"tempPlayer.volume: %f", [tempPlayer volume]);
self.audioPlayerAtmo = tempPlayer;
[tempPlayer release];
[audioPlayerAtmo play];
btAtmo.selected = YES;
}
else // player exists
{
// ...
}
Does someone have an idea why the level is so low on the iPhone while everything is fine in the simulator and on the iPad?
Thanks in advance for your help.
Tech data:
XCode 3.2.4
iPhone 4 (Vers. 4.1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定将音频路由到正确的扬声器吗?
Are you sure you're routing the audio to the correct speaker?
对于 iOS7,AudioSessionSetProperty 已弃用。 Foundry 在以下帖子中的答案展示了如何针对 iOS7 执行此操作:
https://stackoverflow.com/a/18808124/1949877< /a>
For iOS7 AudioSessionSetProperty is deprecated. The answer in the following post by foundry shows how to do this for iOS7:
https://stackoverflow.com/a/18808124/1949877