我想用dailymotion用mpmovieplayercontroller打开一个视频。我尝试过Dailymotion SDK,但它似乎只是将视频嵌入到uiwebview中。我想知道是否有一个dailymotion解析器来获取视频链接,就像hcyoutubeparser或ytvvimeoextractor。
答案 0 :(得分:1)
-(NSDictionary*)getInfoForDailyMotionVideo:(NSString*)videoId
{
NSString *urlString = [NSString stringWithFormat:@"http://www.dailymotion.com/embed/video/%@", videoId];
NSURL *URL = [NSURL URLWithString:urlString];
NSData * data = [[NSData alloc] initWithContentsOfURL:URL];
NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *str;
NSRange startRange = [html rangeOfString:@"var info = {"];
str = [html substringFromIndex:startRange.location];
NSRange endRange = [str rangeOfString:@"{"];
str = [str substringFromIndex:endRange.location];
endRange = [str rangeOfString:@"},"];
NSString *jsonString = [str substringToIndex:endRange.location+1];
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
return result;
}
传递xct647的视频ID,将返回一个字典,其中包含以下与MPMoviePlayerViewController一起使用的键:
"stream_h264_hq_url" = "http://www.dailymotion.com/cdn/H264-848x480/video/xct647.mp4?auth=1371275189-0d67b3d0c242a8b439adf4300014d749";
"stream_h264_ld_url" = "http://www.dailymotion.com/cdn/H264-320x240/video/xct647.mp4?auth=1371275189-f581218251d42809bf13ad96ea6aacb8";
"stream_h264_url" = "http://www.dailymotion.com/cdn/H264-512x384/video/xct647.mp4?auth=1371275189-f905cebbbe96c563beca38ab59132a95";
"stream_hls_url" = "http://www.dailymotion.com/cdn/manifest/video/xct647.m3u8?auth=1371275189-dbdb650a58afe8661ec6aa9628de064f";
对于h264网址使用MPMovieSourceTypeFile,为'hls'网址使用MPMovieSourceTypeStreaming。
答案 1 :(得分:0)
最后一个答案是一个很好的起点,但由于Javascript / JSON语法的变化而不再需要更新:
-(NSDictionary*)getInfoForDailyMotionVideo:(NSString*)videoId{
NSString *urlString = [NSString stringWithFormat:@"http://www.dailymotion.com/embed/video/%@", videoId];
NSURL *URL = [NSURL URLWithString:urlString];
NSData * data = [[NSData alloc] initWithContentsOfURL:URL];
NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *str;
NSRange startRange = [html rangeOfString:@"var config = {"];
str = [html substringFromIndex:startRange.location];
NSRange endRange = [str rangeOfString:@"{"];
str = [str substringFromIndex:endRange.location];
endRange = [str rangeOfString:@"}};"];
NSString *jsonString = [str substringToIndex:endRange.location+1];
jsonString = [jsonString stringByAppendingString:@"}"];
NSError *jsonError;
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&jsonError];
return result;
}
这现在可以工作并返回AVPlayer等的所有相关值......
玩得开心!