使用MPMoviePlayerController播放URL

时间:2011-10-19 05:59:10

标签: ios ios4 mpmovieplayercontroller

我正在使用以下代码在iPhone中播放本地电影文件Movie.m4v MPMoviePlayerController并且工作正常。

现在我已将同一文件放入我的在线服务器mobile.sample.com/Downloads/video/Movie.m4v。我想知道如何在iPhone中使用上述URL播放该电影(不使用uiwebview)。

我怎样才能做到这一点?寻找你的想法。谢谢你的帮助。


- (void) readyPlayer
{
    mp =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

  if ([mp respondsToSelector:@selector(loadState)]) 
  {
    // Set movie player layout
    [mp setControlStyle:MPMovieControlStyleFullscreen];
    [mp setFullscreen:YES];

        // May help to reduce latency
        [mp prepareToPlay];

        // Register that the load state changed (movie is ready)
        [[NSNotificationCenter defaultCenter] addObserver:self 
                       selector:@selector(moviePlayerLoadStateChanged:) 
                       name:MPMoviePlayerLoadStateDidChangeNotification 
                       object:nil];
    }  
  else
  {
    // Register to receive a notification when the movie is in memory and ready to play.
    [[NSNotificationCenter defaultCenter] addObserver:self 
                         selector:@selector(moviePreloadDidFinish:) 
                         name:MPMoviePlayerContentPreloadDidFinishNotification 
                         object:nil];
  }
NSLog(@"ready");
  // Register to receive a notification when the movie has finished playing. 
  [[NSNotificationCenter defaultCenter] addObserver:self 
                        selector:@selector(moviePlayBackDidFinish:) 
                        name:MPMoviePlayerPlaybackDidFinishNotification 
                        object:nil];
}

1 个答案:

答案 0 :(得分:0)

请参阅在线观看或下载您无论如何要消耗网络带宽的数据。如果您未使用UIWebView,则可以执行以下任一操作:

  1. http://allseeing-i.com/ASIHTTPRequest/How-to-use(基本处理 http流)
  2. 在应用程序数据中下载影片,然后播放。放 你自己以后删除它的逻辑。这样做的一大缺点就是如果 大尺寸的电影操作系统然后您可能无法下载它作为您的应用程序 在iOS设备上获得有限的磁盘空间。