我試圖讓YouTube在我的iOS應用程序中運行。我正在成功檢索特定用戶的視頻列表,但我努力實現didSelectRowAtIndexPath,以便將所選視頻嵌入到單獨的viewController中。這裏是我遇到的麻煩的代碼:YouTube視頻GData API
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailController"];
GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
videoArray = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
NSString *tempUrl = [videoArray objectAtIndex:0];
NSLog(@"The URL is:%@",tempUrl);
detailController.videoString = tempUrl;
[self.navigationController pushViewController:detailController animated:YES];
}
我每次運行此,我得到一個斷點「detailController.videoString = tempUrl;」
我能看到tempUrl字符串被填充通過的NSLog如下:
The URL is:GDataMediaContent 0x69c76a0: {url:https://www.youtube.com/v/s36krFdPmYQ?version=3&f=user_uploads&app=youtube_gdata type:application/x-shockwave-flash medium:video isDefault:true expression:full duration:1913}
我怎樣才能從API的GData只提取視頻網址?
在此先感謝您的回覆。
我做了以下修改,現在我得到一個正確的URL字符串:
GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
NSArray *mediaContents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
GDataMediaContent *flashContent = [GDataUtilities firstObjectFromArray:mediaContents withValue:@"application/x-shockwave-flash" forKeyPath:@"type"];
NSLog(@"The URL is:%@",[flashContent URLString]);
detailController.videoString = [flashContent URLString];
這使我從NSLog的以下內容:
The URL is:https://www.youtube.com/v/s36krFdPmYQ?version=3&f=user_uploads&app=youtube_gdata
我仍然然而,在獲得一個斷點「 detailController.videoString = [flashContent URLString];