一、导入音频资源类
#import "AVFoundation/AVAudioSession.h"
二、在播放视频的方法中加一句支持外放的代码
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
参考下面的例子
#pragma mark - 播放视频
- (void)playMovie:(CGRect)videoRect {
// 检查网络设置
BOOL netAvailable = [HelpTool isConnectionAvailable];
if (!netAvailable){
[WSProgressHUD showImage:nil status:@"网络未连接,请检查网络设置"];
return;
}
NSURL *url = [NSURL URLWithString:self.topicModel.videoFullUrl];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.tableView addSubview:player.view];
// 算出tableView当前的偏移
CGPoint offset = self.tableView.contentOffset;
videoRect.origin.y += offset.y;
player.view.frame = videoRect;
player.controlStyle = MPMovieControlStyleEmbedded;
//支持声音外放
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[player prepareToPlay];
[player play];
self.player = player;
}