ios - iOS 5-如何使用网址播放视频

标签 ios ios5 mpmovieplayercontroller

我想在以下链接上播放视频:www.mysite.com/iphone/video.mp4

我使用ios5和MPMoviePlayerController,尝试使用以下代码,但仅显示黑页:

MPMoviePlayerController *player=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:@"http://www.mysite.com/iphone/video.mp4"]];                                               [[player view] setFrame:[self.view.bounds]];                                                                                       [self.view addSubview:[player view]]; [player play]; 

是否可以通过网址字符串播放视频?我有很多视频,所以我不想将它们放到我的项目中,所以我需要从网络上播放它

@Edit:我使用apple's developer site上的示例完成了此操作

它使用流,但解决了我的问题,因为我使用了网址。感谢您的所有答案

最佳答案

试试这个

NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:urlStr];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [self.view addSubview:moviePlayer.view];
    moviePlayer.view.frame = CGRectMake(0, 0, 300, 400);  
    [moviePlayer play];

关于ios - iOS 5-如何使用网址播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10635866/

相关文章:

ios - 从复杂的 C 方法调用 Objective-C 方法?

ios - 让我的简单结构在 Swift 4 中可编码不起作用

objective-c - 在 iPad native 应用程序中每月订阅的 Paypal 付款

objective-c - X代码 4.2 : How To Use Page-Based Application

ios - 为 ScrollView 设置内容偏移量

ios - MPMoviePlayerController:不播放视频

iphone - MPMoviePlayer 标准接口(interface)播放/暂停状态反射(reflect)问题

ios - 在启用 ARC 的情况下在 C 代码中执行 Objective-C 代码时出现运行时内存泄漏警告

iphone - 每次在 Xcode 4.3 中点击按钮时,如何更改按钮的标题?

cocoa-touch - MPMoviePlayerController:如何制作我的视频循环?