2014-03-27 32 views
0

我无法播放我的声音,这是m4a苹果格式。我认为这种格式得到了支持。任何想法可以帮助吗?谢谢 !AVfoundation播放声音m4a格式

#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 

回答

0

一定要在您的设备上测试它,而不是模拟器。在模拟器上有一些配置可以在它运行之前完成。我不确定它是否与m4a格式相关联。有关更多信息,请参阅此answer

最佳教程迄今为止发现:http://www.tutorialspoint.com/ios/ios_audio_video.htm

+0

你能更多地讨论,为什么在设备上运行,而不是在模拟器会尽可能的.m4a而言工作?谢谢。 – Unheilig

+0

看到编辑,希望它会有所帮助。 –