Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sound of App running on iPhone too low

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)

like image 287
MatthiasC Avatar asked Feb 26 '23 20:02

MatthiasC


2 Answers

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

UInt32 doChangeDefaultRoute = 1;        
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);
like image 62
iRyanBell Avatar answered Mar 03 '23 09:03

iRyanBell


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

like image 35
Scott Carter Avatar answered Mar 03 '23 10:03

Scott Carter