代码之家  ›  专栏  ›  技术社区  ›  Sudheesh

MPMoviePlayer在流媒体播放时自动暂停

  •  -1
  • Sudheesh  · 技术社区  · 10 年前

    我正在使用 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];
    

    这是我的代码,用于从给定的url播放视频 mediaURL 。我已尝试添加 MPMoviePlayerPlaybackStateDidChangeNotification 检查状态更改为 MPMoviePlaybackStatePaused ,它也很好。也已检查 MPMovieLoadState 具有 MPMovieLoadStatePlaythroughOK 使用 MPMoviePlayerLoadStateDidChangeNotification 问题是没有得到 MPMovie加载状态播放正常 自动暂停后。 This link

    还有,有没有其他方法可以点击暂停按钮 MPMoviePlayerPlaybackStateDidChange通知 ,因为通知也因为其他原因而被触发。

    1 回复  |  直到 9 年前
        1
  •  0
  •   Sudheesh    10 年前

    我在中的默认“播放/暂停”按钮上方添加了一个透明按钮 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];        
    }
    }