腾讯H5播放器Tcplayer - 增加记忆播放功能

admin

文章最后更新时间:2024年05月17日

TCPlayer

腾讯H5播放器Tcplayer是一款不错的web播放器,被广泛应用到各个站点和应用之中,今天我们来看看怎么在TcplayerH5播放器中添加记忆播放的功能。

首先在web播放器页面中添加一个记忆播放提示框容器的样式

<style type="text/CSS">
#tips{position:absolute; z-index:209910539; right:3%; bottom:10%; background: #000000a6; font-size:15px; color:#FFF; padding:8px; border-radius:4px;}
#go{color: #66CCCC}
.hide{display:none}
</style>

在页面JS代码中加入一段Cookie代码和一段时间转换代码

//Cookie
var cookie={'set':function(name,value,days){var exp=new Date();exp.setTime(exp.getTime()+days*24*60*60*1000);var arr=document.cookie.match(new RegExp('(^| )'+name+'=([^;]*)(;|$)'));document.cookie=name+'='+escape(value)+';path=/;expires='+exp.toUTCString()},'get':function(name){var arr=document.cookie.match(new RegExp('(^| )'+name+'=([^;]*)(;|$)'));if(arr!=null)return unescape(arr[2])},'put':function(urls){var cookie=urls.replace(/[^a-z]+/ig,'');var cookie=cookie.substring(cookie.length-32);return cookie}};

//将缓存已播秒数转换成标准时间格式
function formatSeconds(value){var theTime=parseInt(value);var theTime1=0;var theTime2=0;if(theTime>60){theTime1=parseInt(theTime/60);theTime=parseInt(theTime%60);if(theTime1>60){theTime2=parseInt(theTime1/60);theTime1=parseInt(theTime1%60)}var result=""+prefixInteger(parseInt(theTime),2)+""}else{var result="00:"+prefixInteger(parseInt(theTime),2)+""}if(theTime1>0){result=""+prefixInteger(parseInt(theTime1),2)+":"+result}if(theTime2>0){result=""+prefixInteger(parseInt(theTime2),2)+":"+result}return result}function prefixInteger(num,n){return(Array(n).join(0)+num).slice(-n)}

然后在Tcplayer播放器参数中加入监听播放时间变化并写入缓存.若播放终端已有缓存则自动载入缓存并跳转至该时间刻度

此处为隐藏内容,请评论后查看隐藏内容,谢谢!

最后把记忆播放提示框容器追加进去,还有跳转按钮绑定一下点击事件

$('.vcp-player').append('<div id="tips" class="hide"></div>');

$('.vcp-player').on("click",'#xx',function(e){
	player.currentTime(0);
	player.play();
	$('#tips').addClass("hide")
});

$('.vcp-player').on("click",'#go',function(e){
	player.currentTime(cc);
	player.play();
	$('#tips').addClass("hide")
});

文章版权声明:除非注明,否则均为十八码原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
评论列表 (暂无评论,220人围观)

还没有评论,来说两句吧...

目录[+]