Iphone 从NSURL加载视频

Iphone 从NSURL加载视频,iphone,objective-c,sdk,Iphone,Objective C,Sdk,我正在将视频保存到应用程序中的特定路径 即: 然后我尝试在自定义帧中使用MPMoviePlayerController播放该视频 videoPath = [stand stringForKey:@"videoPathKey"]; NSLog(@"My Video Path is %@", videoPath); MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSUR

我正在将视频保存到应用程序中的特定路径

即:

然后我尝试在自定义帧中使用MPMoviePlayerController播放该视频

videoPath = [stand stringForKey:@"videoPathKey"];
NSLog(@"My Video Path is %@", videoPath);
  MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]];
player.view.frame = CGRectMake(0, 44, 320, 272);
[self.view addSubview:player.view];
[self.view bringSubviewToFront:player.view];
[player play];
这似乎不起作用。视频从未加载。知道为什么吗

是的,我得到了正确的视频路径

NSLOG显示:URL是file:///private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_37794C4E-A3D0-4AC0-9964-A9DEBB61C3E2.mp4

NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"Your VideoName" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:urlStr];
mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
mpMoviePlayerController.view.frame = CGRectMake(0, 0, self.playView.frame.size.width, self.playView.frame.size.height);
[self.playView addSubview:mpMoviePlayerController.view];
[mpMoviePlayerController play];

试试这个

我过去就是这样做的

- (MPMoviePlayerController *) loadFile:(NSString *) fileName intoView:(UIView*) videoView
{
   NSString *thePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp4"];
   NSURL *theurl = [NSURL fileURLWithPath:thePath];
   MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
   [moviePlayer.view setFrame:videoView.bounds];
   [videoView addSubview:moviePlayer.view];
   [moviePlayer setControlStyle:MPMovieControlStyleNone];
   [moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
   moviePlayer.shouldAutoplay = NO;
   return moviePlayer;
}

您应该更改URL以放置方案:

NSURL *movieURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://localhost%@",url]];
您的视频路径将是:file://localhost/private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_66C2B8C6-012C-4608-BA8C-97C7ABA0D721.mp4


我希望这有帮助

请检查它是否播放mp4以外的其他视频格式。
NSURL *movieURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://localhost%@",url]];