我试图在MPMoviePlayerController中播放音频URL(流媒体URL)。(我知道avaudiframework要玩)。我想用MPMoviePlayerController显示带有用户可以暂停,播放,改变音量等控件的视图。这就是我使用MPMoviePlayerController的原因。音频正在播放,但我没有看到媒体播放器。为什么?我使用下面的代码:
-(void)playMovie:(NSURL *)movieURL attachTo:(UIView*)parentView autoPlay:(BOOL)autoplay showControls:(BOOL)showcontrols repeat:(BOOL)autorepeat autoExit:(BOOL)exit
{
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
moviePlayer.controlStyle = showcontrols ? MPMovieControlStyleEmbedded : MPMovieControlStyleNone;
moviePlayer.repeatMode = autorepeat;
moviePlayer.shouldAutoplay = autoplay;
[moviePlayer play];
[parentView addSubview:moviePlayer.view];
}
我认为你需要设置电影播放器视图的框架:
moviePlayer.view.frame = parentView.bounds; // for example
如果你喜欢全屏显示,使用:
[moviePlayer setFullscreen:YES animated:YES];
(并删除[parentView addSubview:moviePlayer.view]
)
当使用MPMoviePlayerController播放音频时,它不会显示任何视图。