Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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 如何设置播放远程视频的MPMoviePlayerController_Ios_Objective C_Video_Mpmovieplayercontroller - Fatal编程技术网

Ios 如何设置播放远程视频的MPMoviePlayerController

Ios 如何设置播放远程视频的MPMoviePlayerController,ios,objective-c,video,mpmovieplayercontroller,Ios,Objective C,Video,Mpmovieplayercontroller,有一个MPMoviePlayerController*movieplayer,它将在服务器上播放远程mp4文件,代码如下: movieplayer = [[MPMoviePlayerController alloc] init]; movieplayer.view.frame = CGRectMake(0, 0, 320, 300); movieplayer.scalingMode = MPMovieScalingModeNone; [self.view addSubview:movieplay

有一个MPMoviePlayerController*movieplayer,它将在服务器上播放远程mp4文件,代码如下:

movieplayer = [[MPMoviePlayerController alloc] init];
movieplayer.view.frame = CGRectMake(0, 0, 320, 300);
movieplayer.scalingMode = MPMovieScalingModeNone;
[self.view addSubview:movieplayer.view];
有两个按钮,abutton,bbutton,abutton调用播放a.mp4

NSString *VideoUrl = @"http://domain.com/a.mp4";
movieplayer.contentURL = [NSURL URLWithString:VideoUrl];
[movieplayer play];
b按钮调用播放b.mp4

NSString *VideoUrl = @"http://domain.com/b.mp4";
movieplayer.contentURL = [NSURL URLWithString:VideoUrl];
[movieplayer play];
我有一些问题:

  • 如何确定正在播放的电影剧本并完成播放?使用停止

  • 如果a.mp4正在播放,我单击b按钮,它将调用播放b.mp4,但仍会播放a.mp4一秒钟,然后跳到b.mp4并播放它

  • 如何预装视频?我觉得预演没用

  • 谢谢

    1)要检查您的MPMoviePlayerController是否正在播放,您可以检查
    播放后台状态
    ,定义为:

    enum {
       MPMoviePlaybackStateStopped,
       MPMoviePlaybackStatePlaying,
       MPMoviePlaybackStatePaused,
       MPMoviePlaybackStateInterrupted,
       MPMoviePlaybackStateSeekingForward,
       MPMoviePlaybackStateSeekingBackward
    };
    typedef NSInteger MPMoviePlaybackState; 
    
    如果其值为
    MPMoviePlaybackStatePlaying
    ,则您的播放机当前正在播放内容

    2)正确,但在播放新内容之前,我建议您停止上一个内容,等待播放器通知(播放器通知您其状态更改),然后播放新内容

    3)播放器已经完成:播放内容时,播放器开始加载内容:只有当缓冲区有足够的数据时,播放才会开始(因此播放器已经完成预加载)。 您可以检查
    loadState
    var,该变量可以具有以下值之一:

    enum {
       MPMovieLoadStateUnknown        = 0,
       MPMovieLoadStatePlayable       = 1 << 0,
       MPMovieLoadStatePlaythroughOK  = 1 << 1,
       MPMovieLoadStateStalled        = 1 << 2,
    };
    typedef NSInteger MPMovieLoadState;
    
    enum{
    MPMovieLoadStateUnknown=0,
    
    MPMovieLoadStatePlayable=1要确定电影播放器播放状态,请添加通知:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playbackStateChanged)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:nil];
    
    您还可以添加通知,以了解播放机何时成功加载视频

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(MPMoviePlayerLoadStateDidChange:)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification
                                               object:nil];
    
    关于简单地知道玩家当前是否正在玩,您可以使用

    MoviePlayer.isPlaying
    
    你是否考虑过为每部电影启动两个不同的电影播放器,然后简单地切换它们?我相信这会使过渡更加顺利