mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-07-14 10:55:06 +08:00
1、微信组件更新vue3.視頻組件更新使用video.js 6.0.0版本。
2、目前mp中視頻組件可以簡單的使用了。
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -8,110 +8,84 @@
|
||||
存在的问题:mediaId 有效期是 3 天,超过时间后无法播放
|
||||
2)重构后的做法:后端接收到微信公众号的视频消息后,将视频消息的 media_id 的文件内容保存到文件服务器中,这样前端可以直接使用 URL 播放。
|
||||
② 体验优化:弹窗关闭后,自动暂停视频的播放
|
||||
|
||||
-->
|
||||
<template>
|
||||
<div>
|
||||
<div @click="playVideo()">
|
||||
<!-- 提示 -->
|
||||
<div @click="playVideo()">
|
||||
<el-icon>
|
||||
<VideoPlay />
|
||||
</el-icon>
|
||||
<div>
|
||||
<Icon icon="ep:video-play" class="mr-5px" />
|
||||
<p>点击播放视频</p>
|
||||
</div>
|
||||
|
||||
<!-- 弹窗播放 -->
|
||||
<el-dialog
|
||||
v-model="dialogVideo"
|
||||
title="视频播放"
|
||||
v-model:visible="dialogVideo"
|
||||
width="40%"
|
||||
append-to-body
|
||||
@close="closeDialog"
|
||||
>
|
||||
<video-player
|
||||
v-if="playerOptions.sources[0].src"
|
||||
class="video-player vjs-custom-skin"
|
||||
ref="videoPlayerRef"
|
||||
:playsinline="true"
|
||||
:options="playerOptions"
|
||||
@play="onPlayerPlay($event)"
|
||||
@pause="onPlayerPause($event)"
|
||||
/>
|
||||
<template #footer>
|
||||
<video-player
|
||||
v-if="dialogVideo"
|
||||
class="video-player vjs-big-play-centered"
|
||||
:src="url"
|
||||
poster=""
|
||||
crossorigin="anonymous"
|
||||
playsinline
|
||||
controls
|
||||
:volume="0.6"
|
||||
:height="320"
|
||||
:playback-rates="[0.7, 1.0, 1.5, 2.0]"
|
||||
/>
|
||||
</template>
|
||||
<!-- 事件,暫時沒用
|
||||
@mounted="handleMounted"-->
|
||||
<!-- @ready="handleEvent($event)"-->
|
||||
<!-- @play="handleEvent($event)"-->
|
||||
<!-- @pause="handleEvent($event)"-->
|
||||
<!-- @ended="handleEvent($event)"-->
|
||||
<!-- @loadeddata="handleEvent($event)"-->
|
||||
<!-- @waiting="handleEvent($event)"-->
|
||||
<!-- @playing="handleEvent($event)"-->
|
||||
<!-- @canplay="handleEvent($event)"-->
|
||||
<!-- @canplaythrough="handleEvent($event)"-->
|
||||
<!-- @timeupdate="handleEvent(player?.currentTime())"-->
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="WxVideoPlayer">
|
||||
// 引入 videoPlayer 相关组件。教程:https://juejin.cn/post/6923056942281654285
|
||||
import { videoPlayer } from 'vue-video-player'
|
||||
<script lang="ts" name="WxVideoPlayer">
|
||||
//升级videojs6.0版本,重寫6.0版本
|
||||
import 'video.js/dist/video-js.css'
|
||||
import { defineComponent } from 'vue'
|
||||
import { VideoPlayer } from '@videojs-player/vue'
|
||||
import 'video.js/dist/video-js.css'
|
||||
import 'vue-video-player/src/custom-theme.css'
|
||||
import { VideoPlay } from '@element-plus/icons-vue'
|
||||
|
||||
const props = defineProps({
|
||||
url: {
|
||||
// 视频地址,例如说:https://www.iocoder.cn/xxx.mp4
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
const videoPlayerRef = ref()
|
||||
const dialogVideo = ref(false)
|
||||
const playerOptions = reactive({
|
||||
playbackRates: [0.5, 1.0, 1.5, 2.0], // 播放速度
|
||||
autoplay: false, // 如果 true,浏览器准备好时开始回放。
|
||||
muted: false, // 默认情况下将会消除任何音频。
|
||||
loop: false, // 导致视频一结束就重新开始。
|
||||
preload: 'auto', // 建议浏览器在 <video> 加载元素后是否应该开始下载视频数据。auto 浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
|
||||
language: 'zh-CN',
|
||||
aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
|
||||
fluid: true, // 当true时,Video.js player 将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
|
||||
sources: [
|
||||
{
|
||||
type: 'video/mp4',
|
||||
src: '' // 你的视频地址(必填)【重要】
|
||||
export default defineComponent({
|
||||
components: {
|
||||
VideoPlayer
|
||||
},
|
||||
props: {
|
||||
url: {
|
||||
// 视频地址,例如说:https://vjs.zencdn.net/v/oceans.mp4
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
],
|
||||
poster: '', // 你的封面地址
|
||||
width: document.documentElement.clientWidth,
|
||||
notSupportedMessage: '此视频暂无法播放,请稍后再试', //允许覆盖 Video.js 无法播放媒体源时显示的默认信息。
|
||||
controlBar: {
|
||||
timeDivider: true,
|
||||
durationDisplay: true,
|
||||
remainingTimeDisplay: false,
|
||||
fullscreenToggle: true //全屏按钮
|
||||
},
|
||||
setup() {
|
||||
// const videoPlayerRef = ref(null)
|
||||
const dialogVideo = ref(false)
|
||||
|
||||
const handleEvent = (log) => {
|
||||
console.log('Basic player event', log)
|
||||
}
|
||||
const playVideo = () => {
|
||||
dialogVideo.value = true
|
||||
}
|
||||
|
||||
return { handleEvent, playVideo, dialogVideo }
|
||||
}
|
||||
})
|
||||
|
||||
const playVideo = () => {
|
||||
dialogVideo.value = true
|
||||
playerOptions.sources[0].src = props.url
|
||||
}
|
||||
const closeDialog = () => {
|
||||
// 暂停播放
|
||||
// videoPlayerRef.player.pause()
|
||||
}
|
||||
// onPlayerPlay(player) {},
|
||||
// // // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
// // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
|
||||
// onPlayerPause(player) {}
|
||||
|
||||
// methods: {
|
||||
// playVideo() {
|
||||
// this.dialogVideo = true
|
||||
// // 设置地址
|
||||
// this.playerOptions.sources[0]['src'] = this.url
|
||||
// },
|
||||
// closeDialog() {
|
||||
// // 暂停播放
|
||||
// this.$refs.videoPlayer.player.pause()
|
||||
// },
|
||||
//
|
||||
// //todo player组件引入可能有问题
|
||||
//
|
||||
// // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
|
||||
// onPlayerPlay(player) {},
|
||||
// // // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
// // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
|
||||
// onPlayerPause(player) {}
|
||||
// }
|
||||
</script>
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
<script setup lang="ts" name="WxVoicePlayer">
|
||||
// 因为微信语音是 amr 格式,所以需要用到 amr 解码器:https://www.npmjs.com/package/benz-amr-recorder
|
||||
|
||||
import BenzAMRRecorder from 'benz-amr-recorder'
|
||||
|
||||
const props = defineProps({
|
||||
|
Reference in New Issue
Block a user