index.vue
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!--
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-23 13:42:35
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-02 17:51:59
* @FilePath: /tswj/src/components/MuiVideo/index.vue
* @Description:
-->
<template>
<div class="video-wrapper">
<div v-if="type === 'video'">
<div :id="'mui-player-' + item.id" class="video-div" />
</div>
<div v-else>
<status :item="item" />
<div :id="'mui-player-' + item.id" class="video-div" />
<video-bar :item="item" :bar-type="1" />
<banner v-if="type === 'bookDetail'" :item="item" />
</div>
</div>
</template>
<script setup>
/**
* 视频组件通用模块
*/
import 'mui-player/dist/mui-player.min.css';
import MuiPlayer from 'mui-player';
import { onMounted } from 'vue';
import banner from './banner';
import videoBar from './videoBar';
import status from './status';
import { useEventListener } from '@/composables';
// 视频基础属性
const props = defineProps({
item: Object,
type: String,
});
// 视频播放事件回调
const emit = defineEmits(['on-play']);
onMounted(() => {
const mp = new MuiPlayer({
container: '#mui-player-' + props.item.id,
title: props.item.title,
src: props.item.video,
poster: props.item.cover,
autoFit: false,
videoAttribute: [
// 声明启用同层播放, 不让会自动全屏播放
{ attrKey: 'webkit-playsinline', attrValue: 'webkit-playsinline' },
{ attrKey: 'playsinline', attrValue: 'playsinline' },
{ attrKey: 'x5-video-player-type', attrValue: 'h5-page' },
],
});
const video = mp.video();
// 监听原生video事件
useEventListener(video, 'play', (event) => {
emit('on-play', {
event,
props: props.item,
});
});
});
</script>
<style lang="less" scoped>
.video-wrapper {
position: relative;
margin: 1rem 0;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.13);
.video-div {
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.video-bar {
color: #713610;
padding: 1rem;
padding-bottom: 0.5rem;
}
}
</style>