Playing a sound with AVAudioPlayer播放本地文件

来源:互联网 发布:2017中国云计算500强 编辑:程序博客网 时间:2024/06/08 08:13
#import <AVFoundation/AVFoundation.h>// Using the AVAudioPlayer to play a sound-(void)loadAndPreparePlayerWithURL:(NSURL *)url error:(NSError **)error{     // Create the player. Assumes player is an ivar of type AVAudioPlayer *    player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];     // Set properties    player.delegate = self; // delegate    // Get ready to play the sound    [ player prepareToPlay ];}-(void)playThePlayer{    // Play !    [ player play ];}-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)myPlayer                      successfully:(BOOL)flag{    if (flag==YES)        [ myPlayer prepareToPlay ];}