iPhone - MPMoviePlayerController - 播放音频时窗口不显示
我正在尝试在 MPMoviePlayerController 中播放音频 URL(流媒体 URL)。 (我知道 AVAudioFramework 可以播放)。我想显示带有控件的视图,用户可以使用 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];
}
I'm trying to play Audio URL (streaming URL) in MPMoviePlayerController.
(I'm aware of AVAudioFramework to play). I want to show the view with controls where user can pause, play, change volume etc with MPMoviePlayerController. That's why I'm using MPMoviePlayerController.
The audio is playing, but I'm not seeing the media player. Why?
I'm using the following code:
-(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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要设置电影播放器视图的框架:
如果您喜欢全屏显示,请使用:(
并删除
[parentView addSubview:moviePlayer.view]
)I think you need to set the frame of the movie player view:
If you prefer a fullscreen display, use:
(and remove the
[parentView addSubview:moviePlayer.view]
)当使用 MPMoviePlayerController 播放音频时,它不会显示任何视图。只有通过视频,它才会显示视图。
When playing audio with MPMoviePlayerController, it won't show any view. Only with video, it will show a view.