iPhone 上运行应用程序的声音太小

发布于 2024-10-01 18:39:49 字数 1015 浏览 0 评论 0原文

我编写了一个可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋你朝朝暮暮 2024-10-08 18:39:49

您确定将音频路由到正确的扬声器吗?

UInt32 doChangeDefaultRoute = 1;        
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);

Are you sure you're routing the audio to the correct speaker?

UInt32 doChangeDefaultRoute = 1;        
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);
迟月 2024-10-08 18:39:49

对于 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文