|
@@ -2,6 +2,8 @@ import { defineComponent, onMounted, reactive, toRefs, watch } from 'vue';
|
|
import { ref } from 'vue';
|
|
import { ref } from 'vue';
|
|
import styles from './index.module.less';
|
|
import styles from './index.module.less';
|
|
|
|
|
|
|
|
+import TCPlayer from 'tcplayer.js';
|
|
|
|
+import 'tcplayer.js/dist/tcplayer.min.css';
|
|
import iconLoop from '../../image/icon-loop.svg';
|
|
import iconLoop from '../../image/icon-loop.svg';
|
|
import iconLoopActive from '../../image/icon-loop-active.svg';
|
|
import iconLoopActive from '../../image/icon-loop-active.svg';
|
|
import iconplay from '../../image/icon-play.svg';
|
|
import iconplay from '../../image/icon-play.svg';
|
|
@@ -37,6 +39,8 @@ export default defineComponent({
|
|
},
|
|
},
|
|
emits: ['loadedmetadata', 'togglePlay', 'ended', 'reset'],
|
|
emits: ['loadedmetadata', 'togglePlay', 'ended', 'reset'],
|
|
setup(props, { emit }) {
|
|
setup(props, { emit }) {
|
|
|
|
+ const videoID = 'video' + Date.now() + Math.floor(Math.random() * 100);
|
|
|
|
+ const videoItem = ref();
|
|
const { item, isEmtry } = toRefs(props);
|
|
const { item, isEmtry } = toRefs(props);
|
|
const data = reactive({
|
|
const data = reactive({
|
|
timer: null as any,
|
|
timer: null as any,
|
|
@@ -71,23 +75,14 @@ export default defineComponent({
|
|
clearTimeout(playTimer);
|
|
clearTimeout(playTimer);
|
|
if (state === 'play') {
|
|
if (state === 'play') {
|
|
playTimer = setTimeout(() => {
|
|
playTimer = setTimeout(() => {
|
|
- elRef.value.play();
|
|
|
|
|
|
+ videoItem.value.play();
|
|
data.playState = 'play';
|
|
data.playState = 'play';
|
|
}, 100);
|
|
}, 100);
|
|
} else {
|
|
} else {
|
|
- elRef.value.pause();
|
|
|
|
|
|
+ videoItem.value.pause();
|
|
data.playState = 'pause';
|
|
data.playState = 'pause';
|
|
}
|
|
}
|
|
- };
|
|
|
|
-
|
|
|
|
- /** 加载成功 */
|
|
|
|
- const onLoadedmetadata = () => {
|
|
|
|
- data.duration = elRef.value.duration;
|
|
|
|
- // // 加载成功后台, 如果是第一次加载, 且是show状态, 则播放
|
|
|
|
- // if (props.show) {
|
|
|
|
- // onToggleAudio('play');
|
|
|
|
- // }
|
|
|
|
- emit('loadedmetadata');
|
|
|
|
|
|
+ emit('togglePlay', data.playState);
|
|
};
|
|
};
|
|
|
|
|
|
/** 改变播放时间 */
|
|
/** 改变播放时间 */
|
|
@@ -100,19 +95,42 @@ export default defineComponent({
|
|
}, 300);
|
|
}, 300);
|
|
};
|
|
};
|
|
|
|
|
|
- /** 播放结束 */
|
|
|
|
- const onEnded = () => {
|
|
|
|
- data.playState = 'pause';
|
|
|
|
- // emit('ended');
|
|
|
|
- };
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
- console.log('加载');
|
|
|
|
|
|
+ videoItem.value = TCPlayer(videoID, {
|
|
|
|
+ appID: '',
|
|
|
|
+ controls: false
|
|
|
|
+ }); // player-container-id 为播放器容器 ID,必须与 html 中一致
|
|
|
|
+ if (videoItem.value) {
|
|
|
|
+ videoItem.value.poster(props.item.coverImg); // 封面
|
|
|
|
+ videoItem.value.src(isEmtry.value ? '' : item.value.content); // url 播放地址
|
|
|
|
+
|
|
|
|
+ // 初步加载时
|
|
|
|
+ videoItem.value.one('loadedmetadata', () => {
|
|
|
|
+ console.log(' Loading metadata');
|
|
|
|
+
|
|
|
|
+ // 获取时长
|
|
|
|
+ data.duration = videoItem.value.duration();
|
|
|
|
+
|
|
|
|
+ emit('loadedmetadata', videoItem.value);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 视频播放时加载
|
|
|
|
+ videoItem.value.on('timeupdate', () => {
|
|
|
|
+ data.currentTime = videoItem.value.currentTime();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 视频播放结束
|
|
|
|
+ videoItem.value.on('ended', () => {
|
|
|
|
+ data.playState = 'pause';
|
|
|
|
+ emit('ended');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
});
|
|
});
|
|
return () => (
|
|
return () => (
|
|
<div class={styles.videoWrap}>
|
|
<div class={styles.videoWrap}>
|
|
<div class={styles.content}>
|
|
<div class={styles.content}>
|
|
<div ref={contetRef} class={styles.contentWrap}>
|
|
<div ref={contetRef} class={styles.contentWrap}>
|
|
- <video
|
|
|
|
|
|
+ {/* <video
|
|
poster={props.item.coverImg}
|
|
poster={props.item.coverImg}
|
|
src={isEmtry.value ? '' : item.value.content}
|
|
src={isEmtry.value ? '' : item.value.content}
|
|
ref={elRef}
|
|
ref={elRef}
|
|
@@ -123,7 +141,16 @@ export default defineComponent({
|
|
data.currentTime = elRef.value.currentTime;
|
|
data.currentTime = elRef.value.currentTime;
|
|
}}
|
|
}}
|
|
onEnded={onEnded}
|
|
onEnded={onEnded}
|
|
- playsinline="false"></video>
|
|
|
|
|
|
+ playsinline="false"></video> */}
|
|
|
|
+ <video
|
|
|
|
+ style={{ width: '100%', height: '100%' }}
|
|
|
|
+ poster={props.item.coverImg}
|
|
|
|
+ src={isEmtry.value ? '' : item.value.content}
|
|
|
|
+ ref={elRef}
|
|
|
|
+ id={videoID}
|
|
|
|
+ preload="auto"
|
|
|
|
+ playsinline
|
|
|
|
+ webkit-playsinline></video>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|