DPlayer.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. user: 'DIYgod',
  44. addition: ['https://cn-south-17-dplayer-49648867.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. this.dplayer = new DPlayer(this.options);
  75. }
  76. },
  77. mounted: function () {
  78. if (this.immediate) {
  79. this.dplayer = new DPlayer(this.options);
  80. }
  81. },
  82. beforeDestroy: function () {
  83. this.dplayer && this.dplayer.destroy();
  84. }
  85. }
  86. </script>
  87. <style>
  88. </style>