6
我正在使用AVPlayer播放視頻。我無法播放.mp4視頻。我正在看這個黑屏。這是我的代碼。無法在AVPlayer中播放mp4視頻
`NSString *filePath = [self.videoArray objectAtIndex:index];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:filePath ofType: @"mp4];
url = [[NSURL alloc] initFileURLWithPath: soundFilePath];
playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.videoGravity = AVLayerVideoGravityResize;
playerViewController.view.frame = self.view.bounds;
playerViewController.showsPlaybackControls = NO;
video=[AVPlayer playerWithURL:url];
playerViewController.player = _video;
playerViewController.view.userInteractionEnabled = false;
[video play];
[self.view addSubview:playerViewController.view];`
使用'NSLog'或調試點檢查filepath或soundFilePath是否有適當的值?還提供更多詳細信息,如錯誤日誌。 –
'NSInvalidArgumentException',原因:'*** - [NSURL initFileURLWithPath:]:nil字符串參數' – Bharathi
因此你的URL是錯誤的。 'self.video_Array'在這個數組中有哪些URL,它是一個HTTP鏈接還是一個本地URL。 –