iPhone - MPMoviePlayerController - 播放音频时窗口不显示

发布于 2024-10-31 16:53:37 字数 1114 浏览 2 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坠似风落 2024-11-07 16:53:37

我认为您需要设置电影播放器​​视图的框架:

moviePlayer.view.frame = parentView.bounds; // for example

如果您喜欢全屏显示,请使用:(

[moviePlayer setFullscreen:YES animated:YES];

并删除 [parentView addSubview:moviePlayer.view]

I think you need to set the frame of the movie player view:

moviePlayer.view.frame = parentView.bounds; // for example

If you prefer a fullscreen display, use:

[moviePlayer setFullscreen:YES animated:YES];

(and remove the [parentView addSubview:moviePlayer.view])

无妨# 2024-11-07 16:53:37

当使用 MPMoviePlayerController 播放音频时,它不会显示任何视图。只有通过视频,它才会显示视图。

When playing audio with MPMoviePlayerController, it won't show any view. Only with video, it will show a view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文