DPlayer.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div class="dplayer-wrap">
  3. <div class="dplayer" ref="dplayer"><button class="load" v-on:click="load">Load demo</button></div>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. immediate: {
  10. type: Boolean,
  11. default: false,
  12. },
  13. options: {
  14. type: Object,
  15. default: () => ({
  16. autoplay: false,
  17. theme: '#FADFA3',
  18. loop: true,
  19. lang: 'zh-cn',
  20. hotkey: true,
  21. preload: 'auto',
  22. logo: 'https://i.loli.net/2019/06/06/5cf8c5d94521136430.png',
  23. volume: 0.7,
  24. mutex: true,
  25. screenshot: true,
  26. subtitle: {
  27. url: 'https://s-sh-17-dplayercdn.oss.dogecdn.com/hikarunara.vtt',
  28. type: 'webvtt',
  29. fontSize: '20px',
  30. bottom: '10%',
  31. color: '#FADFA3'
  32. },
  33. video: {
  34. url: 'https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4',
  35. pic: 'https://i.loli.net/2019/06/06/5cf8c5d9c57b510947.png',
  36. thumbnails: 'https://i.loli.net/2019/06/06/5cf8c5d9cec8510758.jpg',
  37. type: 'auto'
  38. },
  39. danmaku: {
  40. id: '9E2E3368B56CDBB4',
  41. api: 'https://api.prprpr.me/dplayer/',
  42. token: 'tokendemo',
  43. user: 'DIYgod',
  44. addition: ['https://s-sh-17-dplayercdn.oss.dogecdn.com/1678963.json']
  45. },
  46. contextmenu: [
  47. {
  48. text: 'custom1',
  49. link: 'https://github.com/DIYgod/DPlayer'
  50. },
  51. {
  52. text: 'custom2',
  53. click: (player) => {
  54. console.log(player);
  55. }
  56. }
  57. ],
  58. highlight: [
  59. {
  60. time: 20,
  61. text: '这是第 20 秒'
  62. },
  63. {
  64. time: 120,
  65. text: '这是 2 分钟'
  66. }
  67. ]
  68. })
  69. },
  70. },
  71. methods: {
  72. load: function () {
  73. this.options.container = this.$refs.dplayer;
  74. setTimeout(() => {
  75. this.dplayer = new window.DPlayer(this.options);
  76. }, 0);
  77. }
  78. },
  79. mounted: function () {
  80. if (this.immediate) {
  81. setTimeout(() => {
  82. this.dplayer = new window.DPlayer(this.options);
  83. }, 0);
  84. }
  85. },
  86. beforeDestroy: function () {
  87. this.dplayer && this.dplayer.destroy();
  88. }
  89. }
  90. </script>
  91. <style>
  92. </style>