2016-07-29 21 views
6

enter image description here में एमपी 4 वीडियो चलाने में असमर्थ मैं वीडियो चलाने के लिए AVPlayer का उपयोग कर रहा हूं। मैं .mp4 वीडियो नहीं चला सका। मुझे यह ब्लैक स्क्रीन मिल रही है। यहाँ मेरा कोड है।AVPlayer

`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' या डीबग पॉइंट चेक फ़ाइलपैथ या ध्वनिफाइलपाथ का उपयोग करना उचित मूल्य है या नहीं? आपके द्वारा प्राप्त त्रुटि लॉग जैसे अधिक विवरण भी प्रदान करें। –

+0

'एनएसआईएनवालिडअर्ग्यूमेंट एक्सेप्शन', कारण: '*** - [NSURL initFileURLWithPath:]: शून्य स्ट्रिंग पैरामीटर' – Bharathi

+1

तो आपका यूआरएल गलत है। इस सरणी में 'self.video_Array' जो यूआरएल हैं, इसका एक HTTP लिंक या इसका स्थानीय यूआरएल है। –

उत्तर

5

इस कोड मैं इसे आप के लिए काम करेंगे लगता है की कोशिश करो, क्योंकि ऐसा लगता है अपने URL वेब से बंडल अपने लिए नहीं है,।

// 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

धन्यवाद। मैंने एक ही नाम के साथ 2 वीडियो फाइलें जोड़ दी हैं। वह समस्या थी। – Bharathi