播放网络音频并没有那么难,网上查了写资料。代码很简单。
1.第一步 定义全局变量
@property(nonatomic,strong)AVPlayer *player;
2.第二部 懒加载初始化
- (AVPlayer *)player {
if (_player == nil) {
_player = [[AVPlayer alloc] init];
_player.volume = 1.0; // 默认最大音量
}
return _player;
}
3.第三步 创建要播放的资源 记得打开手机的声音 被这坑了一上午
_player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:model.url]];
[_player play];
4.有个音频播放完毕后的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endVoicePlay) name:@"StopVoicePlay" object:nil];