所以我正在使用ASIHTTPRequest从我的FTP下载视频文件。它下载并将其作为文件的目录路径:
/Users/Matt_Sich/Library/Application Support/iPhone Simulator/5.0/Applications/B7366FF2-7592-4ED0-ABC2-46BA111D0FF4/Documents/INWD.mp4
好了,现在我想要播放那个视频......我想这样做很容易,但由于某种原因,我无法让它发挥作用。我得到的只是一个黑色的视图,就是这样。
//NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Park_iPod" ofType:@"mp4"]];
NSURL *url = [NSURL URLWithString:self.PathString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
(注意:self.PathString是我上面提到的下载文件的路径) 它播放来自主捆绑的视频就好了,所以我确定文件路径有问题。
答案 0 :(得分:3)
下载文件后,您需要使用fileURLWithPath
来访问该文件,而不是URLWithString
NSURL *url = [NSURL fileURLWithPath.PathString];
答案 1 :(得分:1)
这会让你获得文件目录......
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
答案 2 :(得分:1)
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:([NSURL fileURLWithPath : self.PathString])];
[moviePlayer setShouldAutoplay:NO];
[moviePlayer setFullscreen:YES animated:YES];
[moviePlayer setScalingMode:MPMovieScalingModeAspectFit];
// Register for the playback finished notification
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(movieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: moviePlayer];
// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object: moviePlayer];
[self.view addSubview: moviePlayer.view];
[moviePlayer.view setFrame: self.view.bounds];
[moviePlayer prepareToPlay];