How to play audio file ios

Posted by Camus on Stack Overflow See other posts from Stack Overflow or by Camus
Published on 2012-10-02T03:33:46Z Indexed on 2012/10/02 3:37 UTC
Read the original article Hit count: 186

Filed under:
|
|
|

I am trying to play an audio file but I can get it working. I imported the AVFoundation framework.

Here is the code:

NSString *fileName = [[NSBundle mainBundle] pathForResource:@"Alarm" ofType:@"caf"];
    NSURL *url = [[NSURL alloc] initFileURLWithPath:fileName];
    NSLog(@"Test: %@ ", url);

    AVAudioPlayer *audioFile = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
    audioFile.delegate = self;
    audioFile.volume = 1;

    [audioFile play];

I am receiving an error nil string parameter

I copied the file to the supporting files folder so the file is there.

Can you guys help me?

Thanks

© Stack Overflow or respective owner

Related posts about ios

Related posts about xcode