0
對於自定義導入的影片文件,pathForResource返回的NSURL對象爲null。MPMoviePlayerController和NSURL對象
-(NSURL *)localMovieURL
{
NSURL *theMovieURL = nil;
NSBundle *bundle = [NSBundle mainBundle];
if (bundle)
{
NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"];
//NSString *moviePath = [bundle pathForResource:@"Movie_01" ofType:@"m4v"];
//NSString *moviePath = [bundle pathForResource:@"Sample" ofType:@"m4v"];
if (moviePath)
{
theMovieURL = [NSURL fileURLWithPath:moviePath];
}
NSLog(@" MMM moviePath = %@", moviePath);
NSLog(@" UUU theMovieURL = %@", theMovieURL);
}
return theMovieURL;
}
考慮從蘋果上面的示例代碼(示例項目名稱 - MoviePlayer)
Movie.m4v自帶樣品和編譯的示例項目發揮的M4V有一點問題都沒有。但是,當我製作Movie.m4v的副本時,將其命名爲Movie_01.m4v並將該文件拖到項目中,MPMoviePlayerController沒有響應。此外,添加的NSLog輸出(以MMM和UUU開頭變爲「... =(null)」,這同樣適用於iMovie自帶的示例m4v「Sample.m4v」。我之前發佈的問題是(here)。我之前的問題涉及一個我自己編寫的項目,它有相同的問題:即使電影文件看起來正確導入,「pathForResource」方法也會返回「nil」。 Xcode和我已經以相同的方式將png照片文件導入(拖動)到項目中,但是png照片可以通過手機和模擬器上的編譯程序按預期方式顯示。 。
感謝您的回答,但我可以在哪裏找到(項目構建步驟>複製資源)? – Stanley 2012-03-15 22:32:09
在項目導航器中選擇項目,選擇目標,點擊「Build Phases」,「Copy Bundle Resources」並添加電影。 – 2012-03-15 22:35:57
關於這兩個問題,第一個問題是幾個小時前,在不同的標題下。第二個是更新並提出另一個問題。舊的與這個鏈接保持聯繫,以防萬一人們不知道爲什麼突然關閉一個問題。 – Stanley 2012-03-15 22:38:10