前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >视频试看5分钟[通俗易懂]

视频试看5分钟[通俗易懂]

作者头像
全栈程序员站长
发布2022-07-22 13:34:17
9670
发布2022-07-22 13:34:17
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

缺陷:用户在控制台能直接拿到视频url地址

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <title>视频试看</title>
</head>
<style type="text/css">
  *{
    margin: 0;
    padding: 0;
  }
  .videobox{
    position: relative;
    width: 100%;
  }
  .videobox video{ width: 100%;  }
  .zhezhao{
    position: absolute;
    background: #000;
    width: 100%;
    top: 0;
    bottom: 0;
    display: none;
    z-index: 9;
    cursor: pointer;
  }
  .shikanjieshu{
    color: #fff;
    position: absolute;
    width: 100%;
    top: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
  }
  .chongxinkaishibox{
    text-align: center;
    font-size: 12px;
  }
  .chongxinkaishibox img{
    width: 30px;
  }
</style>
<body>
<!--   https://y1pindao.com/app/img/mp4/afd83049775b55c1f9e93132d9ff1e3f.mp4 -->
    <div class="videobox">
      <video src="https://y1pindao.com/app/img/mp4/afd83049775b55c1f9e93132d9ff1e3f.mp4"  poster="loading.gif" controls preload="auto" id="player"></video>
      <div class="zhezhao">
        <div class="shikanjieshu">
          <div class="chongxinkaishibox">
            <img src="chongxinkaishi.png" />
            <div>试看结束,点击重新开始</div>
          </div>
        </div>
      </div>
    </div>

    <script type="text/javascript">
         let num = 60*5;
         let pl=document.getElementById("player");  
         pl.addEventListener("timeupdate",function(){
            if(parseInt(pl.currentTime)>=num){
              pl.pause()
              document.getElementsByClassName('zhezhao')[0].style.display = 'block';
              console.log(pl)
              pl.setAttribute('src','')
            }
         })
          document.getElementsByClassName("zhezhao")[0].addEventListener('click',function(){
            console.log('重新开始')
            document.getElementsByClassName('zhezhao')[0].style.display = 'none';
            pl.setAttribute('src','https://y1pindao.com/app/img/mp4/afd83049775b55c1f9e93132d9ff1e3f.mp4')
            pl.currentTime=0;
            pl.play();
          })
    </script>
</body>
</html>

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/125691.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年4月6,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档