|
|
|
@ -4,6 +4,9 @@
@@ -4,6 +4,9 @@
|
|
|
|
|
******Tan |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
//关闭videojs的ga统计
|
|
|
|
|
window.HELP_IMPROVE_VIDEOJS = false; |
|
|
|
|
|
|
|
|
|
if ($('#image_site').get(0)) { |
|
|
|
|
|
|
|
|
|
// 图片浏览
|
|
|
|
@ -185,4 +188,103 @@ if ($('#qrimg').length > 0 && typeof(QRCode) != 'undefined') {
@@ -185,4 +188,103 @@ if ($('#qrimg').length > 0 && typeof(QRCode) != 'undefined') {
|
|
|
|
|
colorLight : "#ffffff", |
|
|
|
|
correctLevel : QRCode.CorrectLevel.L |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var formatDuration = function(duration) { |
|
|
|
|
var str = '00:00:00'; |
|
|
|
|
|
|
|
|
|
var hours = 0, minutes = 0; |
|
|
|
|
|
|
|
|
|
if (duration > 3600) { |
|
|
|
|
hours = Math.floor(duration / 3600); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (duration > 60) { |
|
|
|
|
minutes = Math.floor((duration-hours*3600) / 60); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var seconds = Math.floor(duration - hours*3600 - minutes*60); |
|
|
|
|
|
|
|
|
|
str = hours.toString().padStart(2, '0') + ':' |
|
|
|
|
+ minutes.toString().padStart(2, '0') + ':' |
|
|
|
|
+ seconds.toString().padStart(2, '0'); |
|
|
|
|
|
|
|
|
|
return str; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//视频列表封面图加载
|
|
|
|
|
var getVideoMetaAndShowIt = function(videoId) { |
|
|
|
|
$.ajax({ |
|
|
|
|
url: '/site/videometa', |
|
|
|
|
method: 'GET', |
|
|
|
|
dataType: 'json', |
|
|
|
|
data: { |
|
|
|
|
id: videoId |
|
|
|
|
} |
|
|
|
|
}).done(function(data) { |
|
|
|
|
if (data.code != 1) { |
|
|
|
|
console.warn('视频数据获取失败', data.msg); |
|
|
|
|
}else { |
|
|
|
|
$('#poster_'+videoId).attr('src', data.meta.snapshot); |
|
|
|
|
$('#poster_'+videoId).parent('a').find('.duration').text(formatDuration(data.meta.duration)); |
|
|
|
|
} |
|
|
|
|
}).fail(function(jqXHR, textStatus, errorThrown) { |
|
|
|
|
console.error('视频数据获取失败,错误信息:' + errorThrown); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
$('.video-poster').each(function(index, el) { |
|
|
|
|
var videoId = $(el).attr('data-id'); |
|
|
|
|
getVideoMetaAndShowIt(videoId); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//保存视频数据
|
|
|
|
|
var saveVideoMeta = function(videoId, metaData) { |
|
|
|
|
$.ajax({ |
|
|
|
|
url: '/site/savevideometa', |
|
|
|
|
method: 'POST', |
|
|
|
|
dataType: 'json', |
|
|
|
|
data: { |
|
|
|
|
id: videoId, |
|
|
|
|
meta: metaData |
|
|
|
|
} |
|
|
|
|
}).done(function(data) { |
|
|
|
|
if (data.code != 1) { |
|
|
|
|
console.warn('视频数据保存失败', data.msg); |
|
|
|
|
} |
|
|
|
|
}).fail(function(jqXHR, textStatus, errorThrown) { |
|
|
|
|
console.error('视频数据保存失败,错误信息:' + errorThrown); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//视频播放器
|
|
|
|
|
if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') { |
|
|
|
|
var myPlayer = videojs('my-player', { |
|
|
|
|
controls: true, |
|
|
|
|
autoplay: true, |
|
|
|
|
muted: true, |
|
|
|
|
preload: 'auto' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
myPlayer.one('play', function() { |
|
|
|
|
myPlayer.pause(); |
|
|
|
|
|
|
|
|
|
var canvas = document.createElement('canvas'); |
|
|
|
|
var video = $('video.vjs-tech').get(0); |
|
|
|
|
|
|
|
|
|
//360p
|
|
|
|
|
canvas.width = 640; |
|
|
|
|
canvas.height = 360; |
|
|
|
|
|
|
|
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
|
ctx.drawImage( video, 0, 0, canvas.width, canvas.height ); |
|
|
|
|
|
|
|
|
|
var snapshotImg = canvas.toDataURL('image/jpeg'); |
|
|
|
|
saveVideoMeta($('video.vjs-tech').attr('data-id'), { |
|
|
|
|
duration: myPlayer.duration(), |
|
|
|
|
snapshot: snapshotImg |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
myPlayer.play(); |
|
|
|
|
}); |
|
|
|
|
} |