DPlayer.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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://cn-south-17-dplayer-49648867.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. maximum: 1000,
  44. addition: ['https://api.prprpr.me/dplayer/v3/bilibili?aid=4157142'],
  45. user: 'DIYgod',
  46. bottom: '15%',
  47. unlimited: true
  48. },
  49. contextmenu: [
  50. {
  51. text: 'custom1',
  52. link: 'https://github.com/DIYgod/DPlayer'
  53. },
  54. {
  55. text: 'custom2',
  56. click: (player) => {
  57. console.log(player);
  58. }
  59. }
  60. ],
  61. highlight: [
  62. {
  63. time: 20,
  64. text: '这是第 20 秒'
  65. },
  66. {
  67. time: 120,
  68. text: '这是 2 分钟'
  69. }
  70. ]
  71. })
  72. },
  73. },
  74. methods: {
  75. load: function () {
  76. this.options.container = this.$refs.dplayer;
  77. this.dplayer = new DPlayer(this.options);
  78. }
  79. },
  80. mounted: function () {
  81. if (this.immediate) {
  82. this.dplayer = new DPlayer(this.options);
  83. }
  84. },
  85. beforeDestroy: function () {
  86. this.dplayer && this.dplayer.destroy();
  87. }
  88. }
  89. </script>
  90. <style>
  91. </style>