I use the AVAudioPlayer to play a .caf file. My problem is: it is not loud enough for my purpose. Since the ringer sound of the IPhone is much louder I was wondering how I can archive this volume. I already tried to manipulate the .caf file but with no real success. Any ideas?
The code I use so far:
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: nil];
self.appSoundPlayer = newPlayer;
[newPlayer release];
[appSoundPlayer prepareToPlay];
[appSoundPlayer setVolume: 0.8];
[appSoundPlayer setDelegate: self];
[appSoundPlayer play];
Edit:
[appSoundPlayer setVolume: 1.0];
Thx Martin
You could always set the volume to actual maximum eg:
[appSoundPlayer setVolume: 1.0];
Other than that, you probably will have to edit the file itself.
Martin, have you ensured the system volume is to a maximum? If not, you want to use the MPMusicPlayerController to turn up the system volume to the max, and not just the avaudioplayer maximum. You can turn it up for the length of your sound clip and then set it back to the original volume the user had it set at.
// Import headers. Link to "MediaPlayer Framework"
#import <MediaPlayer/MediaPlayer.h>
//set up audio session
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
NSURL *soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"HsTR_soundEFX_2-1" ofType:@"mp3"]];
audioAlert= [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
audioAlert.delegate = self;
[audioAlert prepareToPlay];//audioAlert is an AVAudioPLayer declared in header
//and whereever you want to play the sound, call the lines below
float currentVolume=[MPMusicPlayerController applicationMusicPlayer].volume; //grab current User volume
[[MPMusicPlayerController applicationMusicPlayer] setVolume:1.0];//set system vol to max
[audioAlert play];
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(setVolumeBackToNormal)userInfo:nil repeats:NO];
//and the setVolumeBackToNormal function calls this line below
[[MPMusicPlayerController applicationMusicPlayer]setVolume:currentVolume];//returns volume to original setting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With