2012-03-16 59 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];