1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 20:52:44 +08:00
2020-06-18 19:52:14 +08:00

108 lines
2.6 KiB
JavaScript

layui.use(['jquery'], function () {
var interval = null;
var intervalTime = 5000;
var position = 0;
var chapterId = $('input[name="chapter.id"]').val();
var planId = $('input[name="chapter.plan_id"]').val();
var userId = $('input[name="user.id"]').val();
var learningUrl = $('input[name="chapter.learning_url"]').val();
var playUrls = JSON.parse($('input[name="chapter.play_urls"]').val());
var requestId = getRequestId();
var options = {
live: true,
autoplay: true,
h5_flv: true,
width: 760,
height: 428
};
if (playUrls.rtmp && playUrls.rtmp.od) {
options.rtmp = playUrls.rtmp.od;
}
if (playUrls.rtmp && playUrls.rtmp.hd) {
options.rtmp_hd = playUrls.rtmp.hd;
}
if (playUrls.rtmp && playUrls.rtmp.sd) {
options.rtmp_sd = playUrls.rtmp.sd;
}
if (playUrls.flv && playUrls.flv.od) {
options.flv = playUrls.flv.od;
}
if (playUrls.flv && playUrls.flv.hd) {
options.flv_hd = playUrls.flv.hd;
}
if (playUrls.flv && playUrls.flv.sd) {
options.flv_sd = playUrls.flv.sd;
}
if (playUrls.m3u8 && playUrls.m3u8.od) {
options.m3u8 = playUrls.m3u8.od;
}
if (playUrls.m3u8 && playUrls.m3u8.hd) {
options.m3u8_hd = playUrls.m3u8.hd;
}
if (playUrls.m3u8 && playUrls.m3u8.sd) {
options.m3u8_sd = playUrls.m3u8.sd;
}
if (userId !== '0' && planId !== '0') {
options.listener = function (msg) {
if (msg.type === 'play') {
start();
} else if (msg.type === 'pause') {
stop();
} else if (msg.type === 'end') {
stop();
}
}
}
var player = new TcPlayer('player', options);
if (position > 0) {
player.currentTime(position);
}
function start() {
if (interval != null) {
clearInterval(interval);
interval = null;
}
interval = setInterval(learning, intervalTime);
}
function stop() {
clearInterval(interval);
interval = null;
}
function learning() {
$.ajax({
type: 'POST',
url: learningUrl,
data: {
request_id: requestId,
chapter_id: chapterId,
plan_id: planId,
interval: intervalTime,
position: player.currentTime(),
}
});
}
function getRequestId() {
var id = Date.now().toString(36);
id += Math.random().toString(36).substr(3);
return id;
}
});