(转)chrome.app实现dplayer播放
By
admin
at 2019-07-23 • 0人收藏 • 1807人看过
感谢 aar培训群 撒旦微笑 分享的源码:
mainfrom.aardio
import win.ui; /*DSG{{*/ var winform = win.form(text="DPlayer";right=759;bottom=469) winform.add( button={cls="button";text="添加切换视频";left=74;top=308;right=314;bottom=391;z=2}; button2={cls="button";text="播放暂停";left=448;top=308;right=700;bottom=391;z=3}; edit={cls="edit";text="https://api.dogecloud.com/player/get.m3u8?vcode=5ac682e6f8231991&userId=17&ext=.m3u8";left=140;top=72;right=629;bottom=99;edge=1;multiline=1;z=1}; edit2={cls="edit";text="http://download.aardio.com/demo/video.aardio";left=140;top=138;right=629;bottom=165;edge=1;multiline=1;z=4} ) /*}}*/ var DPlayer = function(url){ import chrome.app; var app = chrome.app(); app.serverIp = "127.0.0.1"; app.serverPort = "56165"; app.external = { $onLoadUrl = function($,url){ import winex.mouse; winex.mouse.click(app.hwndChrome,100,100);//点击播放视频 } } app.start("\res\DPlayer\index.html?url="++url); app.setPos(,,964,576) return app; } ; //Api http://dplayer.js.org/zh/guide.html#api winform.button.oncommand = function(id,event){ if(!DP){ /**新建播放器并播放**/ DP = DPlayer(winform.edit.text) } else { /**播放器已存在,切换视频**/ DP.doScript($,` dp.switchVideo({ url: '`++winform.edit2.text++`', })`) import winex.mouse; winex.mouse.click(DP.hwndChrome,100,100); } } winform.button2.oncommand = function(id,event){ DP.doScript($,`dp.toggle()`)//播放/暂停 } winform.show() win.loopMessage();
用到的网页index.html:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="css/DPlayer.min.css"> <title>DPlayer</title> <style> *{ margin: 0; padding: 0; } </style> </head> <body> <div id="dplayer"></div> <script src="js/DPlayer.min.js"></script> <script src="js/hls.min.js"></script> <script src="/aardio.js"></script> <script> function GetRequest() { var url = location.search; //获取url中"?"符后的字串 if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("url="); url = decodeURIComponent(strs[1]); // var pt = url.split("//")[0]; // if (pt!==location.protocol) { // console.log(pt) // location.href = pt+"//" + location.host + location.pathname + location.search // } } return url; } var url = GetRequest(); const dp = new DPlayer({ container: document.getElementById('dplayer'), screenshot: false, autoplay: true, hotkey: true, volume: 0.3, video: { url: url } }); dp.fullScreen.request('web')//网页全屏 </script> </body> </html>
可以做成书签, 然后网页就可以调用这个播放器播放视频了
首先,新建个界面
import console; import wsock.tcp.simpleHttpServer; var server = wsock.tcp.simpleHttpServer("127.0.0.1","56165"); console.setTitle("web服务器已启动",server.getUrl()); server.run( function(response,request,session){ if(request){ var url = request.get["url"]; var title = request.get["title"]; thread.invoke( function(url,title){ var DPlayer = function(urls,title){ import chrome.app; var app = chrome.app(); app.external = { $onLoadUrl = function($,url){ import winex.mouse; winex.mouse.click(app.hwndChrome,100,100);//点击播放视频 app.doScript($,`document.title = "`++title++`"`) } } app.start("\res\DPlayer\index.html?url="++urls); app.setPos(,,964,576) win.loopMessage() return app; } ; DPlayer(url,title) },url,title ) } } )
javascript:(function(){$.get("http://127.0.0.1:56165/", { title: document.title, url: PLAYER._DownloadMonitor.dataset.fileData.url } )})();
或者可以添加下面书签,获取到地址,复制到播放界面:
javascript:(function () {prompt("请复制播放地址",PLAYER._DownloadMonitor.dataset.fileData.url)})();
登录后方可回帖