chore:微信小程序实现竖屏是竖屏,横屏是横屏
This commit is contained in:
@@ -108,11 +108,13 @@
|
||||
<view v-else-if="message.type === 'video'" class="video-content">
|
||||
<view class="video-player">
|
||||
<video
|
||||
ref="videoRef"
|
||||
:src="message.url"
|
||||
:poster="message.cover"
|
||||
:controls="true"
|
||||
:autoplay="false"
|
||||
class="video-element"
|
||||
@loadedmetadata="onVideoLoaded(message, $event)"
|
||||
@play="onVideoPlay(message)"
|
||||
@pause="onVideoPause(message)">
|
||||
</video>
|
||||
@@ -1225,6 +1227,42 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
// 视频加载完成事件
|
||||
onVideoLoaded(message, event) {
|
||||
this.$nextTick(() => {
|
||||
let width = 0;
|
||||
let height = 0;
|
||||
|
||||
// H5端:通过video元素获取真实视频宽高
|
||||
// #ifdef H5
|
||||
const video = this.$refs.videoRef;
|
||||
if (video) {
|
||||
width = video.videoWidth || 0;
|
||||
height = video.videoHeight || 0;
|
||||
}
|
||||
// #endif
|
||||
|
||||
// 微信小程序端:通过事件对象获取视频宽高
|
||||
// #ifdef MP-WEIXIN
|
||||
if (event && event.detail) {
|
||||
width = event.detail.width || 0;
|
||||
height = event.detail.height || 0;
|
||||
}
|
||||
// #endif
|
||||
|
||||
if (width && height) {
|
||||
// 判断视频方向:宽度 >= 高度为横屏,否则为竖屏
|
||||
const videoRatio = width >= height ? 'landscape' : 'portrait';
|
||||
console.log(`AI聊天视频宽高比检测: ${width}x${height}, 比例: ${videoRatio}`);
|
||||
|
||||
// 动态设置视频样式
|
||||
// 这里可以添加逻辑来动态调整视频播放器的样式
|
||||
// 例如:message.videoRatio = videoRatio;
|
||||
// 然后在模板中根据message.videoRatio调整样式
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 视频播放
|
||||
onVideoPlay(message) {
|
||||
this.$emit('video-play', message)
|
||||
|
||||
Reference in New Issue
Block a user