2012-01-24 62 views
1

我有一個播放電影的ViewController。如果下載了電影(使用ASI-HTTP-Request),它將採用本地版本。否則,它會從網上傳輸它。這是完全一樣的電影。MPMoviePlayerController無法在文檔文件夾中的電影中工作

流式處理工作得很好,但播放本地文件不起作用。只是一個黑屏,沒有控制。該文件已被正確下載我檢查了md5校驗和。

這是一個大小爲1024x5xx像素的Apple QuickTime視頻(.mov)。

player = [[MPMoviePlayerController alloc] init]; 
[player.view setFrame: self.view.bounds]; 
if (local) { 
    // DOES not work 
    // SHOULD be [NSURL fileURLWithString:...] 
    [player setContentURL: [NSURL URLWithString: @"/path/to/the/movie.mov"]]; 
} else { 
    // does work 
    [player setContentURL: [NSURL URLWithString: @"http://mydomain.tld/path/to/the/movie.mov"]]; 
} 
[self.view addSubview: player.view]; 
[player play] 

我與球員MediaSourceType試圖左右。但它沒有幫助。 爲什麼它不起作用? 我沒有任何錯誤消息,因爲我沒有收到...,有沒有辦法從它得到錯誤消息?

解決方案

我發現我的錯誤。

我用[NSURL URLWithString: @"/the/path/..."]作爲本地路徑。

它與[NSURL fileURLWithPath: @"/the/path/..."]

回答

1

檢查URL到視頻文件。此行返回到Documents目錄的路徑。到文檔目錄

[player setContentURL: [NSURL URLWithString: @"/path/to/the/movie.mov"]]; 

試試這個

[player setContentURL: [NSURL URLWithString: [NSString stringWithFormat:@"%@%@", docPath, @"/path/to/the/movie.mov"]]]; 
+0

的路徑是正確的

NSString* docPath = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 

你的路徑是沒有關係的,我短的代碼。對於那個很抱歉。 電影實際上坐落在緩存目錄中。 '[NSString stringWithFormat:@「%@/Library/Caches/movie.mov」,NSHomeDirectory()]' NSFileManager表示文件存在... – remy

相關問題