我想用 mpmovieplayercontroller 从dailymotion 打开一个视频。我已经尝试过 Dailymotion SDK,但它似乎只是将视频嵌入到 uiwebview。我想知道是否有一个 dailymotion 解析器来获取视频链接,就像 hcyoutubeparser 或 ytvvimeoextractor 一样。
问问题
3384 次
2 回答
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 url 使用 MPMovieSourceTypeFile,对 'hls' url 使用 MPMovieSourceTypeStreaming。
于 2013-06-13T06:11:29.300 回答
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 等的所有相关值......
玩得开心!
于 2017-07-09T19:23:47.987 回答