使用 MPMoviePlayerController 播放 URL

发布于 2024-12-10 19:45:52 字数 1661 浏览 0 评论 0原文

我正在使用下面的代码在 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];
}

I am using the code below to play the local movie file Movie.m4v in iPhone using the
MPMoviePlayerController and which works fine.

Now I have placed the same file into my online server mobile.sample.com/Downloads/video/Movie.m4v. I want to know how I can play that movie using the above URL in the iPhone (not using the uiwebview).

How can I accomplish this? Looking for your thoughts. Thanks for any help.


- (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];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南薇 2024-12-17 19:45:52

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

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

See either watch online or download the data you are anyway going to consume network bandwidth. If you are not using UIWebView then you can do either of the following:

  1. http://allseeing-i.com/ASIHTTPRequest/How-to-use (Basically handle
    the http stream)
  2. Download the movie in your application data and then play it. Put
    your own logic of removing it later. Big downside of this is that if
    movie os of large size then you may fail to download it as you app
    gets a limited disk space on iOS device.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文