Html5 Video Player: vue3 + typescript + dplayer-lite
npm i v3d-player
or
npm i v3d-player mpegts.js hls.js
This is a vue 3.x component that can only be used in vue 3.x
Install v3d-player via npm and import
the plugin as you would any other module.
You will also need to import the stylesheet in some way.
<template>
<div class="demo-player">
<v3d-player
ref="playerRef"
:options="options"
/>
</div>
</template>
<script lang="ts" setup>
import { reactive } from 'vue'
import V3dPlayer from 'v3d-player'
import 'v3d-player/dist/style.css'
const options = reactive({
autoplay: true,
muted: true,
screenshot: true,
preventClickToggle: true,
theme: '#FF3366',
volume: 0.9,
src: '//d2zihajmogu5jn.cloudfront.net/bipbop-advanced/gear3/prog_index.m3u8'
})
</script>
</script>
<style>
.demo-player {
margin: 0 auto;
margin-top: 50px;
width: 640px;
height: 480px;
}
</style>
pause video
play video
close video
seek to specified time
video capture. format: .png
set video speed
toggle between play and pause
get video volume
let value = playerRef.value?.volume()
set video volume
playerRef.value?.volume(0.5, true)
<v3d-player
@canplay="handleCanPlay"
@loadstart="handleLoadStart"
/>
const handleCanPlay = () => {
// console.log('canplay')
}
const handleLoadStart = () => {
// console.log('loadstart')
}
-
Video events
- abort
- canplay
- canplaythrough
- durationchange
- emptied
- ended
- error
- loadeddata
- loadedmetadata
- loadstart
- mozaudioavailable
- pause
- play
- playing
- progress
- ratechange
- seeked
- seeking
- stalled
- suspend
- timeupdate
- volumechange
- waiting
-
Player events
- screenshot
- contextmenu_show
- contextmenu_hide
- notice_show
- notice_hide
- quality_start
- quality_end
- destroy
- resize
- fullscreen
- fullscreen_cancel
- webfullscreen
- webfullscreen_cancel
-
事件流触发的顺序:
- onloadstart
- ondurationchange
- onloadedmetadata
- onloadeddata
- onprogress
- oncanplay
- oncanplaythrough
setup
npm i
dev
npm run dev
build
npm run build