使用MPMoviePlayerController播放URL



我使用以下代码在iPhone中播放本地电影文件Movie.m4vCCD_ 2并且其工作良好。

现在,我已经将相同的文件放入我的在线服务器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];
}

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

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

最新更新