Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS中运行MPMoviePlayServiceWController时禁用全屏模式_Ios_Objective C_Mpmovieplayercontroller - Fatal编程技术网

如何在iOS中运行MPMoviePlayServiceWController时禁用全屏模式

如何在iOS中运行MPMoviePlayServiceWController时禁用全屏模式,ios,objective-c,mpmovieplayercontroller,Ios,Objective C,Mpmovieplayercontroller,我有一个问题:我将mpmovieplayervewcontroller添加到了detailView,但是当我点击按钮打开detailView时,mpmovieplayervewcontroller以全屏模式自动播放。现在我想当点击按钮打开DetailView时,mpmovieplayervewcontroller显示播放按钮而不是自动播放。然后用户点击播放按钮,MPMoviePlayServiceController必须通过调用[自我呈现MoviePlayServiceController激活:

我有一个问题:我将
mpmovieplayervewcontroller
添加到了
detailView
,但是当我点击按钮打开
detailView
时,
mpmovieplayervewcontroller
以全屏模式自动播放。现在我想当点击按钮打开
DetailView
时,
mpmovieplayervewcontroller
显示播放按钮而不是自动播放。然后用户点击播放按钮,MPMoviePlayServiceController必须通过调用
[自我呈现MoviePlayServiceController激活:moviePlayer]全屏运行。我该怎么做?提前谢谢

movieURL = [NSURL URLWithString:previewString];

    moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
    moviePlayer.view.frame = CGRectMake(10,130, 275 , 150);
    [moviePlayer.moviePlayer prepareToPlay] ;
    moviePlayer.moviePlayer.shouldAutoplay = NO;
    moviePlayer.wantsFullScreenLayout = NO;
    moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    //[detailview addSubview:moviePlayer.view];
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];

如果尝试上述代码,moviePlayer将以全屏模式自动运行。现在我希望开始时,moviePlayer不会在全屏模式下自动运行,当用户单击播放按钮时,它将在全屏模式下运行。

请求通知播放状态已更改:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(mpChangedPlaybackState:)
                                             name:MPMoviePlayerPlaybackStateDidChangeNotification
                                           object:nil];
然后检查播放状态以查看是否正在播放:

- (void)mpChangedPlaybackState:(NSNotification *)notification {

    if (self.moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
        // the state has changed to 'playing'
    }
}

记住,当您不再需要知道(最晚,在
视图中将消失:
)时,请删除自己作为观察者的身份。

请求通知播放状态已更改:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(mpChangedPlaybackState:)
                                             name:MPMoviePlayerPlaybackStateDidChangeNotification
                                           object:nil];
然后检查播放状态以查看是否正在播放:

- (void)mpChangedPlaybackState:(NSNotification *)notification {

    if (self.moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
        // the state has changed to 'playing'
    }
}

记住,当您不再需要知道时(最晚,在
视图中将消失:

我尝试了您的代码,但mpChangedPlaybackState()该功能适用于MPMoviePlayerController,而不是MPMoviePlayerServices控制器MPMoviePlayerController包含一个发布这些通知的MPMoviePlayerController。mpChangedPlaybackState是在发布通知时要激发的方法的虚构名称。您可以使用任何您想要的名称,只要它与addObserver选择器匹配。我尝试了-(void)mpChangedPlaybackState:(NSNotification*)通知{if(moviePlayer.moviePlayer.playbackState==MPMoviePlaybackStatePlaying){//状态已更改为“playing”}否则{[self-PresentMoviePlayServiceController激活:moviePlayer];}}但它似乎可以工作。您在条件中似乎只有一个//注释。我的注释是显示您要放置代码。可能只是从方法中的NSLog开始,并在条件中。我只想单击“播放”按钮,它将调用[self-PresentMoviePlayerServiceController激活:moviePlayer];我尝试了您的代码,但mpChangedPlaybackState()函数用于MPMoviePlayerController而不是MPMoviePlayerServiceWController MPMoviePlayerController包含发布这些通知的MPMoviePlayerController。MPChangedPlayerState是发布通知时要激发的方法的虚构名称。只要与addObserver selec匹配,您可以使用任意名称我尝试过-(void)mpChangedPlaybackState:(NSNotification*)通知{if(moviePlayer.moviePlayer.playbackState==MPMoviePlaybackStatePlaying){//状态已更改为“播放”}其他{[自我呈现movieplayervicewcontrolleranimated:moviePlayer];}但它似乎是有效的。您在条件中似乎只有一个//注释。我的注释是要显示您要放置代码。也许只需从方法中的NSLog和条件中的NSLog开始。我只想单击“播放”按钮,它将调用[self-PresentMoviePlayerServiceControlleranimated:moviePlayer];