在视图控制器中,我有一个视频播放和一些背景音乐。如果正在播放背景音乐,视频在循环时会冻结。如果背景音乐没有正常播放,视频循环正常。
下面是我设置视频播放器的方法:
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self getBundleClip:@"MyVideo"]];
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.moviePlayer.shouldAutoplay = YES;
self.moviePlayer.repeatMode = MPMovieRepeatModeOne;音频正在通过此Sound Manager播放。你知道为什么视频会冻结吗?
发布于 2012-09-03 12:43:13
尝试使用在后台AVAudioPlayer中播放音乐和播放相同的时间MPMoviePlayerController,就像下面以重复模式播放AVAudioplayer的代码一样:
首先初始化头文件(.h)中的AVAudioplayer对象,如下所示:
@interface Yourviewcontroller : UIViewController
{
//your some codes after
AVAudioPlayer *audioPlayer;
}
@property (strong, nonatomic) AVAudioPlayer *audioPlayer;在后台实现播放音频文件后,如下代码所示:
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"audio" ofType:@"mp3"]] error:NULL];
audioPlayer.numberOfLoops =-1;//it's play audio repeatedly
audioPlayer.currentTime=0.0f;
[audioPlayer prepareToPlay];在播放音频之后,项目的任何部分,如下面的代码:
[audioPlayer play];你想要停止音频播放器,就像下面的代码:
[audioPlayer stop];https://stackoverflow.com/questions/12241916
复制相似问题