ios - 如何使用 mpmovieplayercontroller 打开 dailymotion 中的视频

标签 ios video mpmovieplayercontroller

我想使用 mpmovieplayercontroller 打开 dailymotion 中的视频。我尝试过 Dailymotion SDK,但它似乎只是将视频嵌入到 uiwebview 中。我想知道是否有一个 dailymotion 解析器可以像 hcyoutubeparser 或 ytvvimeoextractor 一样获取视频链接。

最佳答案

-(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。

关于ios - 如何使用 mpmovieplayercontroller 打开 dailymotion 中的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16092820/

相关文章:

objective-c - 通过 USB 安装 IPA?

ios - 有没有办法在触发后取消 Vision Framework 请求 (VNDetectTextRectanglesRequest)?

javascript - Html5 视频预加载阻止异步脚本

iOS AES-128 加密流媒体与 MPMoviePlayerController

ios - 播放 youtube 视频 iOS 7 时 MPMoviePlayerController 错误 _itemFailedToPlayToEnd

ios - 管理iOS应用常量数据: classes/objects or database

ios - Xcode 7 UIWebView 不加载 url

c - 从 C 中生成的 ffmpeg 进程中优雅地提前退出

swift - 如何在 photoLibrary UIimgaePickerController swift 中过滤扩展

iphone - 在 iOS 3.2 (iPad) 中正确显示和关闭全屏 MPMoviePlayerController