2

我正在努力播放一个视频,它是服务器上视频文件的 url。我有一个视图,其中显示来自 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包含视频 url。

4

2 回答 2

5

Replace your this line : NSURL *url = [NSURL fileURLWithPath:filePath];

with this: NSURL *url=[NSURL URLWithString:filePath]; & then try.

My Code I am using 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];
于 2012-12-27T08:31:34.443 回答
1

如果video file开启server

NSURL *url=[NSURL URLWithString:filePath];

其他应更改movieSourceTypeMPMovieSourceTypeStreaming

self.player.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;

self.player.moviePlayer.fullscreen = YES;

编辑:添加:

  self.player.moviePlayer.shouldAutoplay=YES;

消除 :

 [self.player.moviePlayer play];
于 2012-12-27T08:41:33.157 回答