2016-05-26 29 views
0

我正在使用Xcode 7並且快速查看功能時遇到此錯誤。它說的「fileURL」無法加載快看這裏的數據是我的代碼 //因爲下面一行@file被貼在我fileURL像這樣結束了 -由於fileURLWithPath方法無法加載「fileURL」無法播放AVPlayer視頻的快速查看數據

@"http:/example.com/some_clips/SHAINA%20NC%20NEWS%20X%20180516%201657PM.mp4 -- file:///" see here something file:/// in the end so because of this i am unable to play video. 

如果我使用initWithString和直接給URL,然後給出沒有錯誤,請建議我給我的播放器設置URL以下我已創建請在代碼中閱讀評論也。有沒有人有這個想法。

NSString *localfilepath=[NSString stringWithFormat:@"%@",[managedObject valueForKey:@"clip_path"]]; //here i am getting my URL path upto .mp4 but after below line word -- file gets attached to it because of fileURLWithPath method don't know how to convert that 


NSURL *fileURL = [NSURL fileURLWithPath:localfilepath]; //suggest me this line of code so that i can pass URL to the player here this method is not working 


// create a player 

player = [AVPlayer playerWithURL:fileURL]; //here this fileURL which is going to player is going with that file:/// so giving error and no video runs 

AVPlayerViewController *controller = [[AVPlayerViewController alloc] init]; 

[self addChildViewController:controller]; 
[self.view addSubview:controller.view]; 

controller.view.frame = CGRectMake(10,80,300,300); 
controller.player = player; 
controller.showsPlaybackControls = YES; 
[player pause]; 
+0

'[managedObject valueForKey:@ 「clip_path」]'類? – Larme

+0

它是從哪裏獲取URL的核心數據剪輯的路徑@Larme – vicky

+0

我已經做到了:)我發現它們只是一行代碼只需要在NSUTF8StringEncoding格式中編碼該字符串我將編寫完整的解決方案對此答案 – vicky

回答

0

你應該使用:

NSURL *fileURL = [NSURL URLWithString:localfilepath]; 

相反的:

NSURL *fileURL = [NSURL fileURLWithPath:localfilepath]; 

fileURLWithPath:方法用於創建本地文件(文件位於設備本身)的URL。

+0

感謝您的答案但之前它只是這樣,但是當我使用這種方法時,玩家通過fileURL中的文件URL在調試器中獲得零值,當我們打開客戶端時,它顯示nil @Midhun MP – vicky

+0

@vicky:在url字符串中有一些非法字符的情況下,這就是你將fileURL作爲零的原因。 –

+0

上面的任何一種方式都不是以第一種方式播放視頻,它說nil ....第二個是我的問題 – vicky

0

我已傢伙:)我找到了答案:)這是播放視頻到AVPlayer完整的代碼是在服務器上

//我在這裏取使用核心數據從服務器下載的所有URL管理對象

NSString *localfilepath=[NSString stringWithFormat:@"%@",[managedObject valueForKey:@"clip_path"]]; 

//那麼下面我可以是其編碼爲NSUTF8StringEncoding格式 不要忘記這樣做,否則視頻無法播放,因爲它在我的情況是不是

NSURL *url = [NSURL URLWithString:[localfilepath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

//和下面我分配URL給玩家創造球員

player = [AVPlayer playerWithURL:url]; 

AVPlayerViewController *controller = [[AVPlayerViewController alloc] init]; 

[self addChildViewController:controller]; 
[self.view addSubview:controller.view]; 

controller.view.frame = CGRectMake(10,80,300,300); 
controller.player = player; 
controller.showsPlaybackControls = YES; 
//player.closedCaptionDisplayEnabled = NO; 
[player pause]; 
[player play];