金立gn106刷机,怀孕31周,不再联系 歌词
#import "ViewController.h" #import @interface ViewController () @property (nonatomic, strong) AVAudioPlayer *audioPlayer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //在AppDelegate - application: didFinishLaunchingWithOptions:必须设置,否则真机测试没有声音 // [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; // 1.加载本地的音乐文件 NSURL *url = [[NSBundle mainBundle] URLForResource:@"西游记.mp3" withExtension:nil]; // 2. 创建音乐播放对象 self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; // 3.准备播放 (音乐播放的内存空间的开辟等功能) 不写这行代码直接播放也会默认调用prepareToPlay [self.audioPlayer prepareToPlay]; } // 播放 - (IBAction)playMusic{ [self.audioPlayer play]; } // 暂停 - (IBAction)pause{ [self.audioPlayer pause]; } // 停止 - (IBAction)stop{ // 停止的效果和暂停是相同 [self.audioPlayer stop]; } @end
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
网友评论