The general idea for playing an audio file in iOS 6 was to create an object of AVAudioPlayer and pass the file path to it as follows:
NSURL *fileURL = [NSURL fileURLWithPath:audioFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
if (player == nil)
{
NSLog(@"Error:%@",[error description]);
}
[player prepareToPlay];
player.volume = 1.0f;
[player setNumberOfLoops:0];
[player play];
But lately in iOS 7 the above mentioned code does play the audio file but with a very low volume. Hence the following code needs to be appended before the above mentioned code:
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:NO error:nil];
and as a result the file allocated to the player plays at the specified volume (here the volume is 1.0f i.e.- full volume).
0 Comment(s)