在浏览器中播放m3u8 | 您所在的位置:网站首页 › via浏览器m3u8 › 在浏览器中播放m3u8 |
我自己做了个简单的demo地址:https://github.com/onyas/vip-url-resolve,欢迎star或fork 在浏览器上播放m3u8的视频地址有两种方式: html的video标签的方式,这种方式播放很简单: the5fire m3u8 test the5fire m3u8 test上面的代码,你直接贴到一个index.html中,用safari浏览器打开就可以直接播了。 但是, 目前只能只有Safari支持,通用性并不好。因此还得采用flash来播放,也就下面的第二种方法。 通过开源的swfobject.js以及两个flash组件:OSMF和HLSProvider来播放,上代码: the5fire m3u8 test var flashvars = { // M3U8 url, or any other url which compatible with SMP player (flv, mp4, f4m) // escaped it for urls with ampersands src: escape("http://www.the5fire.com/static/demos/diaosi.m3u8"), // url to OSMF HLS Plugin plugin_m3u8: "http://www.the5fire.com/static/demos/swf/HLSProviderOSMF.swf", }; var params = { // self-explained parameters allowFullScreen: true, allowScriptAccess: "always", bgcolor: "#000000" }; var attrs = { name: "player" }; swfobject.embedSWF( // url to SMP player "http://www.the5fire.com/static/demos/swf/StrobeMediaPlayback.swf", // div id where player will be place "player", // width, height "800", "485", // minimum flash player version required "10.2", // other parameters null, flashvars, params, attrs ); the5fire m3u8 test var flashvars = { // M3U8 url, or any other url which compatible with SMP player (flv, mp4, f4m) // escaped it for urls with ampersands src: escape("http://www.the5fire.com/static/demos/diaosi.m3u8"), // url to OSMF HLS Plugin plugin_m3u8: "http://www.the5fire.com/static/demos/swf/HLSProviderOSMF.swf", }; var params = { // self-explained parameters allowFullScreen: true, allowScriptAccess: "always", bgcolor: "#000000" }; var attrs = { name: "player" }; swfobject.embedSWF( // url to SMP player "http://www.the5fire.com/static/demos/swf/StrobeMediaPlayback.swf", // div id where player will be place "player", // width, height "800", "485", // minimum flash player version required "10.2", // other parameters null, flashvars, params, attrs );通过这三个东西的配合就可以播m3u8了,结果很简单,但是对于我这个对flash外行的人来说还是搜索尝试了良久的。这个代码通过浏览器访问文件的方式是不能用的,你得起一个web服务比如:python -m SimpleHTTPServer。然后访问你存的index.html就能工作了。 结果是不是很简单?不过在搜索的时候也找不到有人提供这样的方案,反而找到很多基于OSMF而开发的收费的flash播放器。基于这三个组件, |
今日新闻 |
推荐新闻 |
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 |