斗鱼简易播放器(带弹幕)
https://s1.ax1x.com/2017/11/25/fC9XV.png如何运行?
下载aardio编程环境,新建一个代码文件,把下面的代码复制进去,点运行即可
import win.ui;
/*DSG{{*/
var winform = win.form(text="斗鱼简易播放器";right=927;bottom=503)
winform.add(
btnView={cls="button";text="查看";left=184;top=456;right=280;bottom=488;db=1;dl=1;z=3};
edRoomId={cls="edit";text="71771";left=64;top=456;right=168;bottom=489;db=1;dl=1;edge=1;multiline=1;z=2};
ffWindow={cls="custom";left=8;top=8;right=920;bottom=448;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1};
static={cls="static";text="房间号";left=16;top=464;right=64;bottom=488;db=1;dl=1;transparent=1;z=4}
)
/*}}*/
import mpvPlayer;
import hpsocket.tcpPullClient;
import crypt;
import inet.whttp;
import web.json;
import thread.command
var mplayer = mpvPlayer(winform.ffWindow);
var tcpPullClient = hpsocket.tcpPullClient()
var whttp = inet.whttp()
var key = "Y237pxTx2In5ayGz"
var sign = function(roomId, t){
var str = "room/" ++ roomId ++ "?aid=androidhd1&cdn=ws&client_sys=android&time=" ++ t ++ key
return crypt.md5(str,false);
}
var getFlvUrl = function(roomId){
var t = tonumber(time())
var url = "http://capi.douyucdn.cn/api/v1/room/" ++ roomId ++ "?aid=androidhd1&cdn=ws&client_sys=android&time=" ++ t ++ "&auth=" ++ sign(roomId, t)
var html = whttp.get( url )
if( html ){
var r = web.json.parse(html)
if( r.error === 0 ){
return r.data.rtmp_url ++ "/" ++ r.data.rtmp_live;
}
}
}
var getUrl = function(roomId="71771"){
var flvUrl = getFlvUrl(roomId)
return flvUrl ? whttp.location( flvUrl, "GET" );
}
var sendData = function(s){
var data = {
int len;
struct msg = {
int len;
word type = 689;
byte cryptedField;
byte reservedField;
byte body[] = s;
byte e;
}
}
data.len = raw.sizeof(data.msg)
data.msg.len = data.len
tcpPullClient.send( data,raw.sizeof(data ))
}
var loginreq = function(roomId){
sendData( "type@=loginreq/roomid@=" ++ roomId ++ "/" )
}
var joingroup = function(roomId){
sendData( "type@=joingroup/rid@=" ++ roomId ++ "/gid@=-9999/" )
}
var keepLive = function(){
sendData( "type@=mrkl/" )
}
tcpPullClient.onPullReceive = function(hpTcpPullClient,connId,length){
import thread.command
while(
var min, remain = 9, length;
;
remain >= min
) {
remain -= 4;
var buf = {INT len};
if 0 == hpTcpPullClient.peek( buf, 4 ) {
var len = buf.len;
if remain < len return ;
remain -= len;
var bufLen = 4+len
buf = raw.buffer( bufLen )
if 0 == hpTcpPullClient.fetch( buf, bufLen ) {
var s = raw.tostring(buf)
if( string.match( s, `type@=(.+?)/`) == "chatmsg" ){
var nickname = string.match( s, `nn@=(.+?)/`)
var txt = string.match( s, `txt@=(.+?)/`)
if( nickname ? txt ){
thread.command.post( "onReceiveChatmsg", nickname , txt )
}
}
}
}
}
}
var thCmd = thread.command()
thCmd.onReceiveChatmsg = function(nick, txt){
mplayer.setOption("osd-msg1", nick ++ ":" ++ txt );
}
winform.btnView.oncommand = function(id,event){
var roomId = winform.edRoomId.text
var url = getUrl(roomId)
if( url ){
mplayer.command("loadfile", url)
if( tcpPullClient.start( "openbarrage.douyutv.com",8601,false) ){
loginreq( roomId )
joingroup( roomId )
var tmId = winform.addtimer(
15000,
function(hwnd,msg,id,tick){
keepLive()
}
)
}
}
}
winform.show()
win.loopMessage(); 好简易啊!膜拜大佬 辛苦了兄弟 谢谢分享 研究一下 可以的。 66666666666 真心的看不懂
辛苦了兄弟 以为成品呢
页:
[1]
2