【问题标题】:MPMoviePlayer automatically pauses when streamingMPMoviePlayer 在流式传输时自动暂停
【发布时间】:2016-04-29 02:16:18
【问题描述】:

我正在使用MPMoviePlayerViewController 播放来自服务器的视频流,其他一切正常。我的问题是,当我播放视频时,它会自动播放并在没有可播放内容时自动进入暂停状态,并且在加载内容后不播放。

movieController = [[MPMoviePlayerViewController alloc] init];
movieController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[movieController.moviePlayer setContentURL:mediaURL];
[movieController.moviePlayer prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];
[movieController.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[movieController.moviePlayer setFullscreen:YES];
[movieController.moviePlayer setShouldAutoplay:YES];
[movieController.moviePlayer play];
[self presentMoviePlayerViewControllerAnimated:movieController];

这是我用于从mediaURL 给出的网址播放视频的代码。我尝试添加MPMoviePlayerPlaybackStateDidChangeNotification 以检查状态更改为MPMoviePlaybackStatePaused,它也可以正常工作。还检查了MPMovieLoadStateMPMovieLoadStatePlaythroughOK 使用MPMoviePlayerLoadStateDidChangeNotification 问题是自动暂停后没有得到MPMovieLoadStatePlaythroughOKThis link

除了MPMoviePlayerPlaybackStateDidChangeNotification,还有什么方法可以让暂停按钮点击,因为通知也会因为其他原因被触发。

【问题讨论】:

    标签: ios objective-c video-streaming mpmovieplayercontroller mpmovieplayer


    【解决方案1】:

    我在MPMoviePlayerViewController 的默认播放/暂停按钮上方添加了一个透明按钮,如下所示。

    CGRect frame = CGRectZero;
    CGFloat width = 100, height= 50;
    frame.origin.x = CGRectGetHeight(movieController.moviePlayer.view.frame)/2 - (width/2);
    frame.origin.y = CGRectGetWidth(movieController.moviePlayer.view.frame) - height;
    frame.size = CGSizeMake(width, height);
    UIButton* playButton = [[UIButton alloc] initWithFrame:frame];
    playButton.backgroundColor = [UIColor clearColor];
    [playButton addTarget:self action:@selector(playButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
    [movieController.moviePlayer.view addSubview:playButton];
    
    
    - (void) playButtonTapped:(UIButton*) sender {
    if (APP_DELEGATE.movieController.moviePlayer.playbackState == 1) {
        [APP_DELEGATE.movieController.moviePlayer pause];        
    }
    else if (APP_DELEGATE.movieController.moviePlayer.playbackState == 2)
    {
        [APP_DELEGATE.movieController.moviePlayer play];        
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-09-25
      • 1970-01-01
      • 2016-01-12
      • 2015-10-26
      • 1970-01-01
      • 2021-03-03
      • 2014-07-15
      • 1970-01-01
      • 2022-10-06
      相关资源
      最近更新 更多