| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <template>
- <div class="video-container-wrap">
- <div class="player">
- <video-player
- ref="videoPlayer"
- :playsinline="false"
- :options="playerOptions"
- class="video-player vjs-custom-skin"
- @play="onPlayerPlay($event)"
- @pause="onPlayerPause($event)"
- @statechanged="playerStateChanged($event)"
- ></video-player>
- </div>
- </div>
- </template>
- <script>
- // 引入样式
- import { videoPlayer } from 'vue-video-player'
- import 'video.js/dist/video-js.css'
- export default {
- components: {
- videoPlayer
- },
- props: {
- videoUrl: { type: String, default: '' },
- state: { type: Boolean, default: false },
- poster: { type: String, default: '' }
- },
- data() {
- return {
- playerOptions: {
- autoplay: false, // 如果true,浏览器准备好时开始回放。
- muted: false, // 默认情况下将会消除任何音频。
- loop: false, // 导致视频一结束就重新开始。
- preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
- language: 'en',
- aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
- fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
- sources: [
- {
- type: 'video/mp4',
- src: this.videoUrl // 你的m3u8地址(必填)
- }
- ],
- poster: this.poster,
- // poster: 'https://surmon-china.github.io/vue-quill-editor/static/images/surmon-3.jpg', // 你的封面地址
- width: document.documentElement.clientWidth,
- notSupportedMessage: this.$t('material.noPlay') // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
- }
- }
- },
- computed: {
- player() {
- return this.$refs.videoPlayer.player
- }
- },
- watch: {
- // 更改视频源 videoUrl从弹出框组件传值
- videoUrl(val, oldVal) {
- if (val === oldVal) {
- return
- }
- if (val !== '') {
- this.playerOptions.sources[0].src = val
- }
- },
-
- // 弹出框关闭后暂停 否则一直在播放 state从弹出框组件传值
- state(val, oldVal) {
- if (val === oldVal) {
- return
- }
- this.$refs.videoPlayer.player.pause()
- },
- poster(val, oldVal) {
- // 检测它的变化,来改变视频封面
- if (val === oldVal) {
- return
- }
- this.playerOptions.poster = val
- }
- },
- methods: {
- onPlayerPlay(player) {},
- onPlayerPause(player) {},
- playerStateChanged(player) {}
- }
- }
- </script>
- <style lang="scss">
- .video-container-wrap {
- .player {
- .video-js .vjs-big-play-button {
- /*
- 播放按钮换成圆形
- */
- height: 2em;
- width: 2em;
- line-height: 2em;
- border-radius: 1em;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- }
- }
- }
- </style>
|