0

I cannot play my sound which is m4a apple format. I thought the format was supported though. Any idea that could help ? Thank you !

#import "PhoneViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface PhoneViewController ()
@property (strong, nonatomic) AVAudioPlayer *optique2000Audio;
@end

@implementation PhoneViewController

- (IBAction)cinq {
    NSString *backgroundMusicPath = [[NSBundle mainBundle] pathForResource:@"optique2000" ofType:AVFileTypeAppleM4A];
    NSURL *backgroundMusicURL = [NSURL URLWithString:backgroundMusicPath];
    NSError *error;
    self.optique2000Audio = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:&error];
    [self.optique2000Audio play];
}

@end
Ambroise Collon
  • 3,839
  • 3
  • 18
  • 37

1 Answers1

0

Be sure to test it on your device rather than the simulator. There are some configuration to do on your simulator before it works. I'm not sure if it's linked to the m4a format. For more information, see this answer.

Best tutorial found so far : http://www.tutorialspoint.com/ios/ios_audio_video.htm

Community
  • 1
  • 1
Ambroise Collon
  • 3,839
  • 3
  • 18
  • 37
  • Can you elaborate more on as to why running on device and not on simulator would work as far as .m4a is concerned? Thanks. – Unheilig Mar 27 '14 at 02:20