@pause="onPause"
@ended="onEnded"
@error="onError"
@timeupdate="onTimeUpdate"
></video>
<view class="uni-btn-v">
<button
type="primary"
@click="play"
>
播放
</button>
</view>
<view class="uni-btn-v">
<button
type="primary"
@click="pause"
>
暂停
</button>
</view> <view class="uni-btn-v">
<button
type="primary"
@click="setSrc(_src)"
>
换源
</button>
</view>
<view class="uni-btn-v">
<button
type="primary"
@click="seek(10)"
>
跳转到指定位置
</button>
</view>
<view class="uni-btn-v">
<button
type="primary"
@click="requestFullScreen(requestFullScreenOptions)"
>
进入全屏
</button>
</view>
<view class="uni-btn-v">
<button
type="primary"
@click="exitFullScreen"
>
退出全屏
</button>
</view>
<view class="uni-btn-v">
<button
type="primary"
@click="stop"
>
停止
</button>
</view>
<view class="uni-btn-v">
<button
type="primary"
@click="sendDanmu('ioio')"
>
发送弹幕
</button>
</view>
<view class="uni-btn-v">
<button
type="primary"
@click="playbackRate(2)"
>
设置倍速
</button>
</view>
</template>
<script lang="ts" setup>
import { ref, onMounted } from "vue"
import { onShow } from "@dcloudio/uni-app"
const src = ref('../../../static/VIDEO/TEST.mp4')
const _src = '../../../static/VIDEO/TEST.mp4'
const videoContext = uni.createVideoContext("test")
const isPause = ref(false)
const isPlaying = ref(false)
const initialTime = ref(0)
const _initialTime = ref(6)
const play = () => {
console.log("play")
videoContext?.play()
}
// 属性
const setSrc = (io : string) => {
src.value = '../../../static/VIDEO/TEST.mp4';
videoContext?.play()
}
const pause = () => {
console.log("pause");
videoContext?.pause();
}
const seek = (pos: number) => {
console.log("seek -> " + pos)
videoContext?.seek(pos)
}
const requestFullScreen = (options: RequestFullScreenOptions | null) => {
console.log("requestFullScreen -> " + options)
videoContext?.requestFullScreen(options)
}
const exitFullScreen = () => {
console.log("exitFullScreen")
videoContext?.exitFullScreen()
}
const stop = () => {
console.log("stop")
// uni.getElementById<UniVideoElement>("test")?.stop() //泛型写法测试
videoContext?.stop();
}
const sendDanmu = function (danmu: Danmu) {
console.log("sendDanmu -> " + danmu)
videoContext?.sendDanmu(danmu)
}
const playbackRate = function (rate: number) {
console.log("playbackRate -> " + rate)
videoContext?.playbackRate(rate)
}
const onPlay = (res : UniEvent) => {
console.log(res.type);
isPlaying.value = true;
isPause.value = false;
}
const onPause = (res : UniEvent) => {
console.log(res.type);
isPlaying.value = false;
isPause.value = true;
}
const onEnded = (res : UniEvent) => {
console.log(res.type, 'iooi');
}
const onError = (res : UniEvent) => {
console.log(res);
}
const onTimeUpdate = (res : UniEvent) => {
const time = res.detail.currentTime
if (time > 0) {
}
}
onShow(() => {
console.log(videoContext)
})
</script>