【问题标题】:Play video from NSDocumentDirectory从 NSDocumentDirectory 播放视频
【发布时间】:2012-04-01 08:14:13
【问题描述】:

我的应用有问题

我正在我的应用程序中下载一个 zip 并将其添加到 NSDocumentDirectory,这个 zip 包含一些图像和一个电影。

我可以访问和显示所有图像,但我无法播放视频

如果我的视频在捆绑目录中,我使用此代码,我可以播放视频

代码: NSString *path = [[NSBundle mainBundle] pathForResource:@"videoName" ofType:@"mov"]; MPMoviePlayerViewController *viewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; [self presentMoviePlayerViewControllerAnimated:viewController];

如果我的视频在捆绑目录中,它就可以工作,但我尝试了很多方法来播放来自 NSDocumentDirectory 的视频。

谁能帮帮我?

谢谢。

【问题讨论】:

  • 您是否为您的视频资源使用了正确的路径?
  • 贴出你用来获取文档路径的代码,也许我们可以得到答案。
  • 我的代码:NSString *fileURLWithPath:movie = [_documentsDir stringByAppendingPathComponent:@"1/1.mov"]; NSURL *movieURL = [NSURL fileURLWithPath:movie]; MPMoviePlayerViewController *viewController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL]; [self presentMoviePlayerViewControllerAnimated:viewController]; [viewController 发布];但我不知道如何,现在它的工作! \o/
  • 但我还有一个问题,我需要从 youtube 播放视频,但它不起作用,我该如何调整此代码来播放 youtube 视频?

标签: video zip document nsbundle movieplayer


【解决方案1】:

对于 Youtube 视频,您可以将 url 发送到共享应用程序,这将在 iOS 的 YouTube.app 中打开视频

NSString *stringURL = @"http://www.youtube.com/watch?v=K8ecN36Ffpc";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

这也适用于其他类型的 youtube 网址

NSString *stringURL = @"http://www.youtube.com/v/K8ecN36Ffpc";

【讨论】:

  • 是的,我知道如何像这样打开,但我想在不离开我的应用的情况下打开一个 youtube 视频
猜你喜欢
  • 1970-01-01
  • 2014-05-09
  • 2013-06-20
  • 2016-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多