|
|
|
@ -212,8 +212,62 @@ var formatDuration = function(duration) {
@@ -212,8 +212,62 @@ var formatDuration = function(duration) {
|
|
|
|
|
return str; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//自动为列表页视频生成封面图并保存
|
|
|
|
|
var noSnapVideos = []; |
|
|
|
|
if ($('#pr-player').length > 0 && typeof(videojs) != 'undefined') { |
|
|
|
|
var myPlayer = videojs('pr-player', { |
|
|
|
|
controls: false, |
|
|
|
|
autoplay: false, |
|
|
|
|
muted: true, |
|
|
|
|
preload: 'auto' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
var mc_video_id = ''; |
|
|
|
|
var tryToGetVideoSnapshot = function() { |
|
|
|
|
if (noSnapVideos.length == 0) {return false;} |
|
|
|
|
|
|
|
|
|
var videoItem = noSnapVideos.pop(); |
|
|
|
|
mc_video_id = videoItem.id; |
|
|
|
|
|
|
|
|
|
console.log(mc_video_id, videoItem.url); |
|
|
|
|
try { |
|
|
|
|
myPlayer.src(videoItem.url); |
|
|
|
|
myPlayer.play(); |
|
|
|
|
}catch(err){ |
|
|
|
|
console.error('自动生成视频封面图失败', err); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
myPlayer.on('playing', function() { |
|
|
|
|
myPlayer.pause(); |
|
|
|
|
|
|
|
|
|
if (typeof(mc_video_id) != 'undefined' && mc_video_id) { |
|
|
|
|
var height = myPlayer.videoHeight(), width = myPlayer.videoWidth(), |
|
|
|
|
aspect = height / width; |
|
|
|
|
var canvas = document.createElement('canvas'); |
|
|
|
|
var video = $('video.vjs-tech').get(0); |
|
|
|
|
|
|
|
|
|
canvas.width = Math.ceil(360/aspect); |
|
|
|
|
canvas.height = 360; //360p
|
|
|
|
|
|
|
|
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
|
ctx.drawImage( video, 0, 0, canvas.width, canvas.height ); |
|
|
|
|
|
|
|
|
|
var snapshotImg = canvas.toDataURL('image/jpeg'); |
|
|
|
|
saveVideoMeta(mc_video_id, { |
|
|
|
|
duration: myPlayer.duration(), |
|
|
|
|
snapshot: snapshotImg |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
tryToGetVideoSnapshot(); //go next
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
setInterval(tryToGetVideoSnapshot, 1000); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//视频列表封面图加载
|
|
|
|
|
var getVideoMetaAndShowIt = function(videoId) { |
|
|
|
|
var getVideoMetaAndShowIt = function(videoId, videoUrl) { |
|
|
|
|
$.ajax({ |
|
|
|
|
url: '/site/videometa', |
|
|
|
|
method: 'GET', |
|
|
|
@ -223,7 +277,8 @@ var getVideoMetaAndShowIt = function(videoId) {
@@ -223,7 +277,8 @@ var getVideoMetaAndShowIt = function(videoId) {
|
|
|
|
|
} |
|
|
|
|
}).done(function(data) { |
|
|
|
|
if (data.code != 1) { |
|
|
|
|
console.warn('视频数据获取失败', data.msg); |
|
|
|
|
console.warn(data.msg); |
|
|
|
|
noSnapVideos.push({id: videoId, url: videoUrl}); |
|
|
|
|
}else { |
|
|
|
|
$('#poster_'+videoId).attr('src', data.meta.snapshot); |
|
|
|
|
$('#poster_'+videoId).parent('a').find('.duration').text(formatDuration(data.meta.duration)); |
|
|
|
@ -234,8 +289,9 @@ var getVideoMetaAndShowIt = function(videoId) {
@@ -234,8 +289,9 @@ var getVideoMetaAndShowIt = function(videoId) {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
$('.video-poster').each(function(index, el) { |
|
|
|
|
var videoId = $(el).attr('data-id'); |
|
|
|
|
getVideoMetaAndShowIt(videoId); |
|
|
|
|
var videoId = $(el).attr('data-video-id'), |
|
|
|
|
videoUrl = $(el).attr('data-video-url'); |
|
|
|
|
getVideoMetaAndShowIt(videoId, videoUrl); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//保存视频数据
|
|
|
|
@ -266,7 +322,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
@@ -266,7 +322,7 @@ if ($('#my-player').length > 0 && typeof(videojs) != 'undefined') {
|
|
|
|
|
preload: 'auto' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
myPlayer.one('play', function() { |
|
|
|
|
myPlayer.one('playing', function() { |
|
|
|
|
myPlayer.pause(); |
|
|
|
|
|
|
|
|
|
var height = myPlayer.videoHeight(), width = myPlayer.videoWidth(), |
|
|
|
|