1.导框架
#import <AVFoundation/AVFoundation.h>
2.创建对象
{
AVAudioPlayer *_audioPlayer; //音乐播放器对象
}
3.播放/暂停/停止
//play
//AVAudioPlayer:音乐播放器
//需要添加系统的框架AVFoundation.framework
if (_audioPlayer == nil) {
//1.要播放的文件的路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"说谎" ofType:@"mp3"];
//2.把文件路径封装成一个url。
NSURL *url = [NSURL fileURLWithPath:path];
_audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
}
//音乐播放器播放前,需要有一个预加载的过程
[_audioPlayer prepareToPlay];
[_audioPlayer play];
//pause
[_audioPlayer pause];
//stop
[_audioPlayer stop];
_audioPlayer = nil;
本文介绍如何使用AVFoundation框架在iOS应用中实现音乐播放器的基本功能,包括播放、暂停及停止操作。
6444

被折叠的 条评论
为什么被折叠?



