video.nvue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. return {
  21. 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",
  22. fil: true,
  23. list: [{
  24. text: '要显示的文本',
  25. color: '#FF0000',
  26. time: 9
  27. }]
  28. }
  29. },
  30. onReady() {
  31. this.context = uni.createVideoContext("video1", this);
  32. },
  33. methods: {
  34. onstart(e) {
  35. console.log("onstart:" + JSON.stringify(e));
  36. },
  37. onpause(e) {
  38. console.log("onpause:" + JSON.stringify(e));
  39. },
  40. onfinish(e) {
  41. console.log("onfinish:" + JSON.stringify(e));
  42. },
  43. onfail(e) {
  44. console.log("onfail:" + JSON.stringify(e));
  45. },
  46. fullscreenchange(e) {
  47. console.log("fullscreenchange:" + JSON.stringify(e));
  48. },
  49. waiting(e) {
  50. console.log("waiting:" + JSON.stringify(e));
  51. },
  52. timeupdate(e) {
  53. console.log("timeupdate:" + JSON.stringify(e));
  54. },
  55. play() {
  56. this.context.play();
  57. },
  58. pause() {
  59. this.context.pause();
  60. },
  61. seek() {
  62. this.context.seek(20);
  63. },
  64. stop() {
  65. this.context.stop();
  66. },
  67. fullScreen() {
  68. this.context.requestFullScreen({
  69. direction: 90
  70. });
  71. },
  72. exitFullScreen() {
  73. this.context.exitFullScreen();
  74. },
  75. sendDanmu() {
  76. this.context.sendDanmu({
  77. text: '要显示的弹幕文本',
  78. color: '#FF0000'
  79. });
  80. },
  81. playbackRate() {
  82. this.context.playbackRate(2);
  83. }
  84. }
  85. }
  86. </script>
  87. <style>
  88. .video {
  89. width: 750rpx;
  90. /* #ifdef H5 */
  91. width: 100%;
  92. /* #endif */
  93. height: 400rpx;
  94. background-color: #808080;
  95. }
  96. .btn {
  97. margin-top: 5px;
  98. margin-bottom: 5px;
  99. }
  100. </style>