2014-10-13 65 views
0

我正在使用MPMoviePlayerController在iOS上播放視頻。MPMoviePlayerController顯示空白屏幕第二次啓動

我第一次打網址和視頻下載到文件目錄&打得不錯。

第二次我檢查視頻是否已經下載或沒有。 如果不是那麼它去服務器&下載它, 如果是的話,那麼它應該從文件目錄訪問它,並應播放視頻。

但是當我從文檔目錄中獲取視頻時,它會顯示路徑以及視頻文件名,但是 它不播放視頻。

直接將其移至上一個空白屏幕視圖。

我在做什麼錯。

在此先感謝。

這是我的代碼。

NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 
       NSString *docDir = [arrayPaths objectAtIndex:0]; 
       NSString* destinationDirectoryPath=docDir; 
       NSString *clientPathString = [[NSString alloc] initWithFormat:@"/user"]; 
       destinationDirectoryPath = [destinationDirectoryPath stringByAppendingString:clientPathString]; 
       destinationDirectoryPath = [destinationDirectoryPath stringByAppendingString:@"/video1/"]; 
       NSString *filePath=[NSString stringWithFormat:@"%@",userVideoDTO.learnerid];//@"author"; 
       filePath=[destinationDirectoryPath stringByAppendingString:[NSString stringWithFormat:@"%@.mp4",filePath]]; 
       NSLog(@"FilePath new one :- %@",filePath); 

self.url = [NSURL fileURLWithPath:filePath]; 

那麼這self.url傳遞給作爲的MPMoviePlayerController

self.mp =[[MPMoviePlayerController alloc] initWithContentURL:self.url]; 

[self.view addSubview:mp.view]; 
[self.mp play]; 

我缺少什麼。 任何人都可以讓我知道。 這個相同的代碼在較低版本的iOS上工作正常。像iOS7和以下。 不在iOS8上。

在此先感謝。

回答

0

我一直有類似的問題,事實證明,在iOS7和以下包含視圖控制器沒有它的-viewWillDisappear:animated:在電影播放器​​被顯示之前調用,而在iOS8中,並且進一步,它確實得到調用。我正在釋放播放器並取消訂閱-viewWillDisappear:animated:中的通知,這次我必須將此代碼移動到dealloc

+0

謝謝KVS,我會試試 – Sagar

相關問題