diff --git a/bricks/header.tmpl b/bricks/header.tmpl index 167f442..48f0c53 100644 --- a/bricks/header.tmpl +++ b/bricks/header.tmpl @@ -5,22 +5,22 @@ - +--> diff --git a/bricks/video.js b/bricks/video.js index f9ba8c9..86dcee1 100644 --- a/bricks/video.js +++ b/bricks/video.js @@ -26,6 +26,7 @@ bricks.VideoBody = class extends bricks.Layout { bricks.Video = class extends bricks.Layout { /* { + title: vtype: url: fullscreen: @@ -63,6 +64,7 @@ bricks.Video = class extends bricks.Layout { } } auto_play(){ + return; schedule_once(this._auto_play.bind(this), 0.5); } _auto_play(){ @@ -73,6 +75,10 @@ bricks.Video = class extends bricks.Layout { play(){ console.log('Video:play() called....'); this.player.play(); + // this.player.muted(false); + } + unmuted(){ + this.player.muted(false); } set_fullscreen(){ if (this.fullscreen){ @@ -100,26 +106,32 @@ bricks.Video = class extends bricks.Layout { this.player.on('ended', this.report_ended.bind(this)); this._set_source(); this.player.ready(this.set_fullscreen.bind(this)); - /* + console.log('=======', this.autoplay, '========'); if (this.autoplay){ - this.player.autoplay = true; - this.player.muted = true; - this.player.ready(this.auto_play.bind(this)); - } else { - console.log('autoplay=', this.autoplay, this.auto_play); - // this.player.ready(this.auto_play.bind(this)); + this.auto_play(); } - */ } } report_ended(){ + if (this.play_status != 'playok'){ + returnl + } + this.play_status = 'playend'; this.dispatch('play_end',{src:this.video_body.cur_url,type:this.video_body.cur_vtype}); } report_playok(){ + if (this.play_status != ''){ + return; + } + this.play_status = 'playok'; console.log(this.video_body.cur_url, 'play ok'); this.dispatch('play_ok', {src:this.video_body.cur_url,type:this.video_body.cur_vtype}); } report_error(){ + if (this.play_status != ''){ + return; + } + this.play_status = 'playfailed'; console.log(this.video_body.cur_url, 'play failed', this.err_cnt, 'times'); this.dispatch('play_failed', {'src':this.video_body.cur_url, type:this.video_body.cur_vtype}); } @@ -129,6 +141,7 @@ bricks.Video = class extends bricks.Layout { src:this.video_body.cur_url, type:this.video_body.cur_vtype }); + this.play_status = ''; } } set_source(url, vtype){ @@ -146,8 +159,94 @@ bricks.Video = class extends bricks.Layout { this.video_body.cur_url = url; this.video_body.cur_vtype = vtype; this._set_source(); + this.play(); } } + set_url(url){ + this.set_source(url); + } } +bricks.Iptv = class extends bricks.VBox { + /* + { + iptv_data_url: + playok_url: + playfailed_url: + } + */ + constructor(opts){ + super(opts); + schedule_once(this.build_subwidgets.bind(this), 0.1); + } + async build_subwidgets(){ + console.log('build_subwidgets called'); + var jc = new bricks.HttpJson(); + this.deviceid = bricks.deviceid('iptv') + this.user_data = await jc.httpcall(this.iptv_data_url, { + params:{ + deviceid:this.deviceid + }, + method:'GET' + }); + console.log('this.user_data =', this.user_data); + this.video = new bricks.Video({ + autoplay:true, + url:this.user_data.url + }); + this.title_w = new bricks.Text({text:this.user_data.tv_name, wrap:false}); + this.add_widget(this.title_w); + this.add_widget(this.video); + this.video.bind('play_ok', this.report_play_ok.bind(this)); + this.video.bind('play_failed', this.report_play_failed.bind(this)); + } + async report_play_ok(){ + console.log(this.user_data, 'channel playing ...', this.playok_url); + if (this.playok_url){ + var ht = new bricks.HttpText(); + var resp = ht.httpcall(this.playok_url,{ + params:{ + deviceid:this.deviceid, + channelid:this.user_data.id + }, + method:"GET" + }); + if (resp != 'Error'){ + console.log('report playok ok'); + } else { + console.log('report playok failed'); + } + } else { + console.log('this.playok_url not defined', this.playok_url); + } + } + async report_play_failed(){ + console.log(this.user_data, 'channel play failed ...'); + if (this.playfailed_url){ + var ht = new bricks.HttpText(); + var resp = ht.httpcall(this.playfailed_url,{ + params:{ + deviceid:this.deviceid, + channelid:this.user_data.id + }, + method:"GET" + }); + if (resp != 'Error'){ + console.log('report playfailed ok'); + } else { + console.log('report playfailed failed'); + } + } else { + console.log('this.playfailed_url not defined', this.playfailed_url); + } + } + setValue(data){ + this.user_data = data; + this.title_w.set_text(data.tv_name); + this.video.set_url(data.url); + } + + +} bricks.Factory.register('Video', bricks.Video); +bricks.Factory.register('Iptv', bricks.Iptv);