Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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_Video_Mpmovieplayercontroller - Fatal编程技术网

Ios MPMoviePlayerController不';不要加载我的视频

Ios MPMoviePlayerController不';不要加载我的视频,ios,video,mpmovieplayercontroller,Ios,Video,Mpmovieplayercontroller,我正在尝试使用MPMoviePlayerController显示视频,但无法使其正常工作。 我的视频在我的服务器上。所以我试着用这种方式来展示它: -(void) playMovieAtURL: (NSURL*) theURL { moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL]; moviePlayer.view.frame = self.view.bounds; movi

我正在尝试使用MPMoviePlayerController显示视频,但无法使其正常工作。 我的视频在我的服务器上。所以我试着用这种方式来展示它:

-(void) playMovieAtURL: (NSURL*) theURL {
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL];
    moviePlayer.view.frame = self.view.bounds;
    moviePlayer.controlStyle = MPMovieControlModeDefault;
    moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    moviePlayer.fullscreen = YES;

    [self.view addSubview:moviePlayer.view];
    [moviePlayer prepareToPlay];
    [moviePlayer play];
}
moviePlayer是我的viewController的一个属性。 给出的URL是正确的(在safari中测试)。 我的视频是.mov视频

当我的函数被调用时,我只是有一个黑屏。 控件没有出现,我认为视频没有加载,因为在应用程序的状态栏中,网络活动指示器没有显示

欢迎任何帮助

编辑

我刚刚注意到,尝试从设备的safari应用程序访问视频会导致以下结果:

编辑2

我的视频是480 × 850和MPMoviePlayerController仅支持高达640 x 480的视频。 所以不能用这个框架玩。 我是否必须调整视频大小,或者是否有其他框架可用于显示视频? 我只需要一个非常简单的播放器…

这样做:

-(void)playMovieAtURL:: (NSURL*) url
{

    moviePlayer =  [[MPMoviePlayerController alloc]
                 initWithContentURL:url];

    [[NSNotificationCenter defaultCenter] addObserver:self
                   selector:@selector(moviePlayBackDidFinish:)
                   name:MPMoviePlayerPlaybackDidFinishNotification
                   object:moviePlayer];

    moviePlayer.controlStyle = MPMovieControlStyleDefault;
    moviePlayer.shouldAutoplay = YES;
    [self.view addSubview:moviePlayer.view];
    [moviePlayer setFullscreen:YES animated:YES];
    [moviePlayer play];
    [self.view bringSubviewToFront:moviePlayer.view];
}


- (void) moviePlayBackDidFinish:(NSNotification*)notification {
    MPMoviePlayerController *player = [notification object];
    [[NSNotificationCenter defaultCenter] 
      removeObserver:self
      name:MPMoviePlayerPlaybackDidFinishNotification
      object:player];

    if ([player
        respondsToSelector:@selector(setFullscreen:animated:)])
    {
        [player.view removeFromSuperview];
    }
}

//你可以这样做

 -(void)playMovie:(id)sender
 {
   NSURL *url = [NSURL URLWithString:
  @"http://www.xxxx.com/movie.mov"];

_moviePlayer =  [[MPMoviePlayerController alloc]
             initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
               selector:@selector(moviePlayBackDidFinish:)
               name:MPMoviePlayerPlaybackDidFinishNotification
               object:_moviePlayer];

_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}

//目标操作通知方法

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
   MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
  removeObserver:self
  name:MPMoviePlayerPlaybackDidFinishNotification
  object:player];

if ([player
    respondsToSelector:@selector(setFullscreen:animated:)])
{
    [player.view removeFromSuperview];
}
}

谢谢你的回答。现在,将显示控件。但我得到了无限的负荷。。。我的视频从未播放过,而且我的状态中仍然没有任何活动指示器添加了播放功能并将Subviews带到了前台。我在PlayMovie自然中使用过此功能,但它没有任何改变。将显示MPMoviePlayerController视图,控制器(预览、播放、下一步)也会显示,但在顶部工具栏中,靠近“完成”按钮的地方,会用活动指示器写上“加载…”。我错过了一个框架?委托协议?顺便问一下,在显示MPMoviePlayerController的视图后调用
moviePlayBackDidFinish:
是否正常?请查看我的编辑,我刚刚尝试从设备的safari应用程序访问视频。谢谢您的回答。它与莱克斯的类似。你能看一下评论吗?哦,好吧,好吧,我没有检查他的答案。。。“我的视频从未播放过,但我得到了无限加载…这里无限加载意味着..你能解释清楚吗?我的意思是:MPMoviePlayerController视图会显示,控制器也会显示(预览、播放、下一步),但在顶部工具栏中,靠近“完成”按钮的地方写着@“加载…”。。。“带有活动指示器。但视频永远不会显示(也可能永远不会加载)。可能是由于网络连接…如果你的网络非常慢,加载也需要时间。嗯。。。不确定,它甚至在模拟器上也不工作(而从safari加载只需要10秒左右)