123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <template>
- <view class="ui-video-wrap">
- <video
- :id="`sVideo${uid}`"
- class="radius"
- :style="[{ height: height + 'rpx' }]"
- :src="src"
- controls
- object-fit="contain"
- :enable-progress-gesture="state.enableProgressGesture"
- :initial-time="initialTime"
- x5-video-player-type="h5"
- x-webkit-airplay="allow"
- webkit-playsinline="true"
- @error="videoErrorCallback"
- @timeupdate="timeupdate"
- @play="play"
- @pause="pause"
- @ended="end"
- :poster="poster"
- :autoplay="autoplay"
- >
-
- <cover-view :style="{ transform: 'translateX(' + moveX + 'px)' }" />
-
- </video>
- </view>
- </template>
- <script setup>
-
- import { reactive, nextTick, getCurrentInstance } from 'vue';
- import sheep from '@/sheep';
- const vm = getCurrentInstance();
-
- const state = reactive({
-
- enableProgressGesture: true,
-
-
- enableProgressGesture: false,
-
- showModal: false,
- });
-
- const props = defineProps({
- moveX: {
- type: [Number],
- default: 0,
- },
-
- uid: {
- type: [Number, String],
- default: 0,
- },
-
- height: {
- type: Number,
- default: 300,
- },
-
- width: {
- type: Number,
- default: 750,
- },
-
- initialTime: {
- type: Number,
- default: 1,
- },
- src: {
- type: String,
- default: '',
- },
- poster: {
- type: String,
- default: 'https://img1.baidu.com/it/u=1601695551,235775011&fm=26&fmt=auto',
- },
- autoplay: {
- type: Boolean,
- default: false,
- }
- });
-
- const emits = defineEmits(['videoTimeupdate']);
-
- const timeupdate = (e) => {
- emits('videoTimeupdate', e);
- };
- const videoErrorCallback = (e) => {
- console.log('视频错误信息:', e.target.errMsg);
- };
-
- const play = () => {
- console.log('视频开始');
- };
-
- const pause = () => {
- console.log('视频暂停');
- };
-
- const end = () => {
- console.log('视频结束');
- };
-
- const startPlay = () => {
- nextTick(() => {
- const video = uni.createVideoContext(`sVideo${props.index}`, vm);
- video.play();
- });
- };
-
- const pausePlay = () => {
- const video = uni.createVideoContext(`sVideo${props.index}`, vm);
- video.pause();
- };
-
- const beforePlay = () => {
- uni.getNetworkType({
- success: (res) => {
- const networkType = res.networkType;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- startPlay();
- },
- });
- };
-
- defineExpose({
- pausePlay,
- });
- </script>
- <style lang="scss" scoped>
- .radius {
- width: 100%;
- }
- .ui-video-wrap {
- display: flex;
- align-items: center;
- justify-content: center;
- .poster-wrap {
- position: relative;
- width: 100%;
- height: 100%;
- .poster-image {
- width: 100%;
- height: 100%;
- }
- .play-icon {
- position: absolute;
- left: 50%;
- top: 50%;
- width: 80rpx;
- height: 80rpx;
- transform: translate(-50%, -50%);
- background-color: rgba($color: #000000, $alpha: 0.1);
- border-radius: 50%;
- }
- }
- }
- </style>
|