2012-03-16 83 views
0

所以我使用ASIHTTPRequest从我的FTP下载视频文件。它下载和我得到这个为目录文件路径:播放下载的视频MPMovieController

/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是路径,我上面提到的下载的文件) 它起着从主束就好,所以我敢肯定,有一些错误的文件路径的视频。

回答

3

一旦你下载你的文件,你需要使用fileURLWithPath访问该文件,而不是URLWithString

NSURL *url = [NSURL fileURLWithPath.PathString]; 
1

这将让你的文件目录...

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
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];