video.nvue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div>
  3. <video id='video1' class="video" :src="src" autoplay="false" duration="" controls="true" :danmu-list="list"
  4. danmu-btn="true" enable-danmu="true" :loop="true" muted="true" initial-time="" direction="-90"
  5. show-mute-btn="true" @play="onstart" @pause="onpause" @ended="onfinish" @error="onfail" @waiting="waiting"
  6. @timeupdate="timeupdate" @fullscreenchange="fullscreenchange"></video>
  7. <button class="btn" @click="play">播放</button>
  8. <button class="btn" @click="pause">暂停</button>
  9. <button class="btn" @click="seek">跳转到指定位置</button>
  10. <button class="btn" @click="stop">停止</button>
  11. <button class="btn" @click="fullScreen">全屏</button>
  12. <button class="btn" @click="exitFullScreen">退出全屏</button>
  13. <button class="btn" @click="playbackRate">设置倍速</button>
  14. <button class="btn" @click="sendDanmu">发送弹幕</button>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. data: {
  20. src: "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-lite.m4v",
  21. fil: true,
  22. list: [{
  23. text: '要显示的文本',
  24. color: '#FF0000',
  25. time: 9
  26. }]
  27. },
  28. onReady() {
  29. this.context = uni.createVideoContext("video1", this);
  30. },
  31. methods: {
  32. onstart(e) {
  33. console.log("onstart:" + JSON.stringify(e));
  34. },
  35. onpause(e) {
  36. console.log("onpause:" + JSON.stringify(e));
  37. },
  38. onfinish(e) {
  39. console.log("onfinish:" + JSON.stringify(e));
  40. },
  41. onfail(e) {
  42. console.log("onfail:" + JSON.stringify(e));
  43. },
  44. fullscreenchange(e) {
  45. console.log("fullscreenchange:" + JSON.stringify(e));
  46. },
  47. waiting(e) {
  48. console.log("waiting:" + JSON.stringify(e));
  49. },
  50. timeupdate(e) {
  51. console.log("timeupdate:" + JSON.stringify(e));
  52. },
  53. play() {
  54. this.context.play();
  55. },
  56. pause() {
  57. this.context.pause();
  58. },
  59. seek() {
  60. this.context.seek(20);
  61. },
  62. stop() {
  63. this.context.stop();
  64. },
  65. fullScreen() {
  66. this.context.requestFullScreen({
  67. direction: 90
  68. });
  69. },
  70. exitFullScreen() {
  71. this.context.exitFullScreen();
  72. },
  73. sendDanmu() {
  74. this.context.sendDanmu({
  75. text: '要显示的弹幕文本',
  76. color: '#FF0000'
  77. });
  78. },
  79. playbackRate() {
  80. this.context.playbackRate(2);
  81. }
  82. }
  83. }
  84. </script>
  85. <style>
  86. .video {
  87. width: 750rpx;
  88. height: 400rpx;
  89. background-color: #808080;
  90. }
  91. .btn {
  92. margin-top: 5px;
  93. margin-bottom: 5px;
  94. ;
  95. }
  96. </style>