2013-11-24 65 views
0

我是新手。我正嘗試從數組中調用視頻。我知道我正在將字符串與對象混合。但我不知道用什麼來代替它。這是不正確的代碼行:發送'NSArray'到類型爲'NSString'的參數的指針類型不兼容

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: _arrayVidSrc ofType:@".mp4" inDirectory:@"videos"]]; 

我該如何解決?

這裏是整個代碼塊:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.titlelabel.text = self.titlecontents; 
    self.navBar.title = self.titlecontents; 


    //video load from array 
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: _arrayVidSrc ofType:@".mp4"]]; 

    MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
    [self presentMoviePlayerViewControllerAnimated:playercontroller]; 
    playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
    [playercontroller.moviePlayer play]; 
    playercontroller = nil; 


} 
+0

取決於你想要什麼?數組中的0 1 2 3 4 ..n對象? –

+2

NSString _is_是一個對象。你在混合類型。該錯誤告訴你該參數需要一個NSString,但代碼傳遞一個NSArray。我建議對Objective-C有更好的,基本的瞭解,並尋找這個常見的錯誤。在使用pathForRes的SO上必須有數百個例子。 – Anna

+0

我知道這是錯的。我不知道如何解決它。我正嘗試根據用戶在表單元格中點擊的內容設置視頻。所以,如果用戶點擊單元格2,他們會得到視頻2(數組中的#1)。 – CharleyB

回答

2

從我想你想的URL對視頻的陣列的上下文。如果_arrrayVidSrc是一個數組,你應該只傳遞它的元素之一(例如嘗試在代碼不正確的行使用_arrayVidSrc[0]):

NSString * firstVideoFileName = _arrayVidSrc[0]; 
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:firstVideoFileName 
                    ofType:@".mp4"]]; 
+0

這就近了。但是,並不完全。謝謝。我可以根據用戶點擊的表格中的單元格來設置它,而不是將其設置爲數組中的特定數字。 – CharleyB

+0

這就像'NSString * firstVideoFileName = _arrayVidSrc [indexPath.row];'一定有許多數組項目,因爲有單元格。 – Eimantas

相關問題