Player.vue 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="container">
  3. <div class="player">
  4. <video-player class="video-player vjs-custom-skin"
  5. ref="videoPlayer"
  6. :playsinline="false"
  7. :options="playerOptions"
  8. @play="onPlayerPlay($event)"
  9. @pause="onPlayerPause($event)"
  10. @statechanged="playerStateChanged($event)"
  11. >
  12. </video-player>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. //引入样式
  18. import { videoPlayer } from 'vue-video-player'
  19. import '../../node_modules/video.js/dist/video-js.css'
  20. import '../../node_modules/vue-video-player/src/custom-theme.css'
  21. export default {
  22. props: {
  23. videoUrl: String,
  24. state: Boolean
  25. },
  26. data () {
  27. return {
  28. playerOptions: {
  29. // playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
  30. autoplay: false, // 如果true,浏览器准备好时开始回放。
  31. muted: false, // 默认情况下将会消除任何音频。
  32. loop: false, // 导致视频一结束就重新开始。
  33. preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
  34. language: 'zh-CN',
  35. aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
  36. fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
  37. sources: [{
  38. type: 'video/mp4',
  39. src: this.videoUrl// 你的m3u8地址(必填)
  40. }],
  41. // poster: 'https://surmon-china.github.io/vue-quill-editor/static/images/surmon-3.jpg', // 你的封面地址
  42. width: document.documentElement.clientWidth,
  43. notSupportedMessage: '此视频暂无法播放,请稍后再试'// 允许覆盖Video.js无法播放媒体源时显示的默认信息。
  44. }
  45. }
  46. },
  47. watch: {
  48. //更改视频源 videoUrl从弹出框组件传值
  49. videoUrl: function (val) {
  50. if (val !== '') {
  51. this.$refs.videoPlayer.player.src(val)
  52. }
  53. },
  54. //弹出框关闭后暂停 否则一直在播放 state从弹出框组件传值
  55. state: function (val) {
  56. if (val) {
  57. this.$refs.videoPlayer.player.pause()
  58. }
  59. }
  60. },
  61. components: {
  62. videoPlayer
  63. },
  64. methods: {
  65. onPlayerPlay (player) {
  66. },
  67. onPlayerPause (player) {
  68. },
  69. playerStateChanged (player) {
  70. }
  71. },
  72. computed: {
  73. player () {
  74. return this.$refs.videoPlayer.player
  75. }
  76. }
  77. }
  78. </script>
  79. <!-- Add "scoped" attribute to limit CSS to this component only -->
  80. <style type="text/css" scoped>
  81. .container {
  82. background-color: #efefef;
  83. min-height: 100%;
  84. }
  85. </style>