【问题标题】:iPhone - MPMoviePlayerController - Window not showing when playing audioiPhone - MPMoviePlayerController - 播放音频时不显示窗口
【发布时间】:2011-04-11 12:00:34
【问题描述】:

我正在尝试在 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];
}

【问题讨论】:

    标签: iphone media-player audio-streaming


    【解决方案1】:

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

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

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

    [moviePlayer setFullscreen:YES animated:YES];
    

    (并删除[parentView addSubview:moviePlayer.view]

    【讨论】:

    • 我按照你说的添加了。现在它在屏幕中间显示一个窄条,其中包含播放按钮、计时器、进度指示器和音频的持续时间。但它没有显示全屏视图。
    • 这不起作用。它现在根本没有显示视图。它也没有显示完成按钮(即使只显示控件)来关闭音频播放器并返回应用程序。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      相关资源
      最近更新 更多