Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Handling audio files in iOS 7

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 297
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: