我正在努力播放视频,这是服务器上视频文件的网址。我有一个视图,我在其中显示来自Web服务的URL。当我点击url(包含在表格单元格中)时,我想要一个新的视图应该出现在播放视频的电影播放器上。我尝试了MPMoviePlayerViewController
和MPMoviePlayerController
以及两者的各种组合,但我无法在模拟器上播放视频。目前我没有设备,所以请在回答时考虑模拟器和设备。目前我正在使用:
NSURL *url = [NSURL fileURLWithPath:filePath];
self.player= [[ MPMoviePlayerViewController alloc] initWithContentURL:url];
//self.player.navigationController.navigationBar.hidden = YES;
[self.player.moviePlayer prepareToPlay];
//self.player.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
self.player.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.player.moviePlayer.fullscreen = NO;
[self presentModalViewController:self.player animated:NO];
[self.player.moviePlayer play];
filepath
是包含视频网址的nsstring
。
答案 0 :(得分:5)
替换此行:NSURL *url = [NSURL fileURLWithPath:filePath];
这个:NSURL *url=[NSURL URLWithString:filePath];
&然后试试。
我的代码我正在使用MPMOVIEPLAYERVIEWCONTROLLER
:
NSData *geturl = [[videoparsing objectAtIndex:btntag]objectForKey:@"iurl"];
myString = [[NSString alloc] initWithData:geturl encoding:NSASCIIStringEncoding];
NSLog(@"myString..%@",myString);
NSURL *fileURL=[NSURL URLWithString:myString];
NSLog(@"fileURL..%@",fileURL);
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer prepareToPlay];
moviePlayerController.moviePlayer.shouldAutoplay=YES;
[moviePlayerController.moviePlayer play];
答案 1 :(得分:1)
如果video file
上有server
,那么
NSURL *url=[NSURL URLWithString:filePath];
其他应该将movieSourceType
更改为MPMovieSourceTypeStreaming
:
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
另外
self.player.moviePlayer.fullscreen = YES;
编辑:添加:
self.player.moviePlayer.shouldAutoplay=YES;
删除:
[self.player.moviePlayer play];