Sound of App running on iPhone too low

此生再无相见时 提交于 2019-12-23 12:26:00

问题


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)


回答1:


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

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



回答2:


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



来源:https://stackoverflow.com/questions/4164170/sound-of-app-running-on-iphone-too-low

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!