#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 ]; }
Playing a sound with AVAudioPlayer播放本地文件
最新推荐文章于 2022-12-19 17:12:23 发布