video_videoplayer.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  6. <meta name="HandheldFriendly" content="true"/>
  7. <meta name="MobileOptimized" content="320"/>
  8. <title>Hello H5+</title>
  9. <script type="text/javascript" src="../js/common.js"></script>
  10. <script type="text/javascript">
  11. var video = null;
  12. var playing = false;
  13. // H5 plus事件处理
  14. function plusReady(){
  15. // 创建视频播放控件
  16. video = new plus.video.VideoPlayer('video',{
  17. src:'../video/bee.mp4'
  18. });
  19. video.addEventListener('play', function(){
  20. updatePlaying(true);
  21. }, false);
  22. video.addEventListener('pause', function(){
  23. updatePlaying(false);
  24. }, false);
  25. }
  26. document.addEventListener('plusready', plusReady, false);
  27. // 播放
  28. function playVideo1() {
  29. var path = document.getElementById('path1').value;
  30. if(path&&path.length>0) {
  31. video.setOptions({src:path});
  32. video.play();
  33. }
  34. }
  35. function playVideo2() {
  36. var path = document.getElementById('path2').value;
  37. if(path&&path.length>0) {
  38. video.setOptions({src:path});
  39. video.play();
  40. }
  41. }
  42. function updateVideo() {
  43. video.setStyles({direction:0});
  44. }
  45. // 更新为播放状态
  46. function updatePlaying(play) {
  47. playing = play;
  48. document.getElementById('pp').innerText = playing?'暂停':'播放';
  49. }
  50. // 播放/暂停
  51. function ppVideo() {
  52. playing?video.pause():video.play();
  53. }
  54. // 全屏
  55. function fullscreenVideo() {
  56. video.requestFullScreen(-90);
  57. }
  58. // 切换倍速
  59. var ri = 2;
  60. var ra = [0.5,0.8,1.0,1.25,1.5,2];
  61. function switchRate() {
  62. ri++;
  63. if(ri>=ra.length){
  64. ri = 0;
  65. }
  66. video.playbackRate(ra[ri]);
  67. document.getElementById('rate').innerText = '切换倍速('+ra[ri]+')';
  68. }
  69. // 创建子创建覆盖在视频控件上
  70. var wsub = null;
  71. function createSubview(){
  72. if(!wsub) {
  73. var topoffset = document.getElementById('video').offsetTop;
  74. wsub=plus.webview.create('video_videoplayer_sub.html','sub',{top:topoffset,height:'300px',position:'static',scrollIndicator:'none',background:'transparent'});
  75. plus.webview.currentWebview().append(wsub);
  76. }
  77. wsub.isVisible()?wsub.hide():wsub.show();
  78. }
  79. </script>
  80. <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
  81. <style type="text/css">
  82. input {
  83. width:70%;
  84. font-size: 16px;
  85. padding: .2em .2em;
  86. border: 1px solid #00B100;
  87. -webkit-user-select: text;
  88. }
  89. button {
  90. width:20%;
  91. margin:6px 0 6px 6px;
  92. font-size: 16px;
  93. color: #FFF;
  94. background-color: #00CC00;
  95. border: 1px solid #00B100;
  96. padding: .2em 0em;
  97. -webkit-border-radius: 5px;
  98. border-radius: 5px;
  99. }
  100. </style>
  101. </head>
  102. <body>
  103. <br/>
  104. <div id="video" style="width:98%;height:300px;background-color:#000000;margin:auto"></div>
  105. <br/>
  106. <div style="text-align:center; margin:auto;">
  107. <!--<input id="path1" type="text" value="http://vjs.zencdn.net/v/oceans.mp4" placeholder="请输入视频地址,支持mp4/flv格式"/>-->
  108. <input id="path1" type="text" value="https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/%E7%AC%AC1%E8%AE%B2%EF%BC%88uni-app%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D%EF%BC%89-%20DCloud%E5%AE%98%E6%96%B9%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B@20181126.mp4" placeholder="请输入视频地址,支持mp4/flv格式"/>
  109. <button onclick="playVideo1()">播放</button>
  110. <br/>
  111. <input id="path2" type="text" value="http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8" placeholder="请输入视频地址,支持rtmp直播"/>
  112. <button onclick="playVideo2()">直播</button>
  113. </div>
  114. <div id="pp" class="button" onclick="ppVideo()">播放</div>
  115. <div class="button" onclick="fullscreenVideo()">全屏</div>
  116. <div id="rate" class="button" onclick="switchRate()">切换倍速(1)</div>
  117. <div class="button" onclick="updateVideo()">更新direction</div>
  118. <div class="button" onclick="createSubview()">控件上内容显示/隐藏</div>
  119. </body>
  120. </html>