2016-07-29 27 views
6

enter image description here Videoları oynatmak için AVPlayer kullanıyorum. .mp4 videoları oynamadık. Bu siyah ekranı alıyorum. İşte benim kodum.AVPlayer'da mp4 videoları oynatılamıyor

`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];` 
+0

'NSLog' veya hata ayıklama noktası denetimi dosya yolunu kullanma veya soundFilePath uygun bir değere sahip olsun veya olmasın? Ayrıca sahip olduğunuz hata günlüğü gibi daha fazla ayrıntı sağlar. –

+0

'NSInvalidArgumentException', nedeni: '*** - [NSURL initFileURLWithPath:]: nil dizi parametresi' – Bharathi

+1

URL'niz yanlış. 'self.video_Array' bu dizide hangi URL’ler vardır, bir HTTP bağlantısı veya yerel bir URL’si. –

cevap

5

Bu kodu deneyin, bunun sizin için çalışacağını düşünüyorum çünkü URL’niz web’den gelen paket için değil.

// your filepath which is may be "http" type 
NSString *filePath = [self.video_Array objectAtIndex:index]; 
// http to NSURL using string filepath 
NSURL *url= [[NSURL alloc] initWithString:filePath]; 
AVPlayerViewController *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]; 
+0

Teşekkür ederim. Aynı ada sahip 2 video dosyası ekledim. Sorun buydu. – Bharathi

İlgili konular