Package Exports
- liveplayer-wrapper
- liveplayer-wrapper/dist/style.css
Readme
LivePlayer Wrapper
A Vue 3 wrapper component for @liveqing/liveplayer-v3 with enhanced recording and playback control features.
🚀 最新更新
v1.1.3 - 修复了 videojs is not defined 错误:
- ✅ 将
videojs打包到本地库中,不再依赖外部 npm 包 - ✅ 确保
videojs在全局环境中正确可用 - ✅ 优化了构建配置,提高了兼容性
- ✅ 添加了完整的测试示例
🔧 问题修复
如果您之前遇到 Uncaught ReferenceError: videojs is not defined 错误,现在这个问题已经解决。videojs 现在直接打包在库中,无需额外安装。
Features
- 🎥 Video streaming support (HLS, FLV, RTMP, etc.)
- 📹 Screen recording functionality
- 🎮 Playback control (play, pause, volume, fullscreen)
- 🎛️ Customizable UI controls
- 📱 Responsive design
- 🎨 Customizable styling
- 🔧 TypeScript support
Installation
npm install liveplayer-wrapperUsage
Basic Usage
<template>
<div>
<LivePlayerWrapper
:video-url="videoUrl"
:video-title="videoTitle"
@ready="onPlayerReady"
@recordingStart="onRecordingStart"
@recordingStop="onRecordingStop"
@recordingError="onRecordingError"
/>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { LivePlayerWrapper } from 'liveplayer-wrapper'
const videoUrl = ref('https://example.com/stream.m3u8')
const videoTitle = ref('Live Stream')
const onPlayerReady = (player: any) => {
console.log('Player is ready:', player)
}
const onRecordingStart = () => {
console.log('Recording started')
}
const onRecordingStop = () => {
console.log('Recording stopped')
}
const onRecordingError = (error: string) => {
console.error('Recording error:', error)
}
</script>Plugin Installation
import { createApp } from 'vue'
import App from './App.vue'
import LivePlayerWrapper from 'liveplayer-wrapper'
const app = createApp(App)
app.use(LivePlayerWrapper)
app.mount('#app')Global Component Registration
import { createApp } from 'vue'
import App from './App.vue'
import { LivePlayerWrapper } from 'liveplayer-wrapper'
const app = createApp(App)
app.component('LivePlayerWrapper', LivePlayerWrapper)
app.mount('#app')Props
| Prop | Type | Default | Description |
|---|---|---|---|
videoUrl |
string |
"" |
Video stream URL |
videoTitle |
string |
"" |
Video title displayed in top-right corner |
poster |
string |
"" |
Video poster image URL |
alt |
string |
"无信号" |
Alternative text when no video |
autoplay |
boolean |
true |
Auto-play video |
controls |
boolean |
true |
Show control bar |
loop |
boolean |
false |
Loop video |
live |
boolean |
true |
Is live stream (hide progress bar) |
muted |
boolean |
true |
Mute video |
aspect |
string |
"16:9" |
Aspect ratio (or "fullscreen") |
fluent |
boolean |
true |
Smooth mode |
stretch |
boolean |
false |
Stretch video |
hideBigPlayButton |
boolean |
false |
Hide big play button |
waterMark |
string |
"" |
Watermark text |
timeout |
number |
20 |
M3U8 loading timeout (seconds) |
showCustomButton |
boolean |
true |
Show custom buttons |
hideSnapshotButton |
boolean |
false |
Hide snapshot button |
hideFullscreenButton |
boolean |
false |
Hide fullscreen button |
hideFluent |
boolean |
false |
Hide fluent button |
hideStretch |
boolean |
true |
Hide stretch button |
resolution |
string |
"" |
Resolution config (yh,fhd,hd,sd) |
resolutiondefault |
string |
"hd" |
Default resolution |
playbackRates |
number[] |
[0.5, 1, 2, 3] |
Playback rate options |
playbackRate |
number |
1 |
Default playback rate |
hasaudio |
boolean |
undefined |
Has audio (auto-detect) |
hasvideo |
boolean |
undefined |
Has video (auto-detect) |
customButtons |
string |
"录制:vjs-icon-record,开关:vjs-icon-switch" |
Custom toolbar buttons |
autofocus |
boolean |
false |
Auto focus |
dblclickFullscreen |
boolean |
true |
Double-click fullscreen |
language |
string |
"" |
Language (zh-CN/en) |
digitalZoom |
boolean |
false |
Digital zoom |
Events
| Event | Parameters | Description |
|---|---|---|
message |
{ type: string, message: string } |
M3U8 loading failed |
error |
Error |
Player error |
ended |
- | Playback ended |
timeupdate |
number |
Time update (current time) |
pause |
number |
Paused (current time) |
play |
number |
Playing (current time) |
fullscreen |
boolean |
Fullscreen state changed |
snapOutside |
string |
External snapshot (base64) |
snapInside |
string |
Internal snapshot (base64) |
customButtons |
string |
Custom button clicked |
canplay |
number |
Can play (duration in seconds) |
volumechange |
{ volume: number, muted: boolean } |
Volume changed |
ready |
any |
Player ready |
recordingStart |
- | Recording started |
recordingStop |
- | Recording stopped |
recordingError |
string |
Recording error |
Methods
Playback Control
play()- Start playbackpause()- Pause playbacktogglePlay()- Toggle play/pausepaused()- Check if pausedgetCurrentTime()- Get current timesetCurrentTime(time: number)- Set current timegetDuration()- Get video duration
Volume Control
getMuted()- Check if mutedsetMuted(muted: boolean)- Set muted statetoggleMute()- Toggle mutegetVolume()- Get volume (0-1)setVolume(volume: number)- Set volume
Fullscreen Control
isFullscreen()- Check fullscreen staterequestFullscreen()- Enter fullscreenexitFullscreen()- Exit fullscreentoggleFullscreen()- Toggle fullscreen
Recording
startRecording()- Start recordingstopRecording()- Stop recordingtoggleRecording()- Toggle recordingisRecording()- Check recording stategetRecordingTime()- Get recording durationforceStopRecording()- Force stop recordingrecoverFromRecordingError()- Recover from error
Playback Switch
togglePlayback()- Toggle video on/offisPlaying()- Check if video is playing
Other
snap()- Take screenshotgetPlayer()- Get player instance
Example
<template>
<div class="video-container">
<LivePlayerWrapper
ref="playerRef"
:video-url="streamUrl"
:video-title="streamTitle"
:autoplay="true"
:controls="true"
:live="true"
:muted="false"
:aspect="'16:9'"
:show-custom-button="true"
:custom-buttons="'录制:vjs-icon-record,开关:vjs-icon-switch'"
@ready="onPlayerReady"
@recordingStart="onRecordingStart"
@recordingStop="onRecordingStop"
@recordingError="onRecordingError"
@customButtons="onCustomButtonClick"
/>
<div class="controls">
<button @click="startRecording">Start Recording</button>
<button @click="stopRecording">Stop Recording</button>
<button @click="togglePlayback">Toggle Playback</button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { LivePlayerWrapper } from 'liveplayer-wrapper'
const playerRef = ref()
const streamUrl = ref('https://example.com/live.m3u8')
const streamTitle = ref('Live Stream')
const onPlayerReady = (player: any) => {
console.log('Player ready:', player)
}
const onRecordingStart = () => {
console.log('Recording started')
}
const onRecordingStop = () => {
console.log('Recording stopped')
}
const onRecordingError = (error: string) => {
console.error('Recording error:', error)
}
const onCustomButtonClick = (buttonName: string) => {
console.log('Custom button clicked:', buttonName)
}
const startRecording = () => {
playerRef.value?.startRecording()
}
const stopRecording = () => {
playerRef.value?.stopRecording()
}
const togglePlayback = () => {
playerRef.value?.togglePlayback()
}
</script>
<style scoped>
.video-container {
max-width: 800px;
margin: 0 auto;
}
.controls {
margin-top: 20px;
text-align: center;
}
.controls button {
margin: 0 10px;
padding: 10px 20px;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.controls button:hover {
background: #0056b3;
}
</style>Development
# Install dependencies
npm install
# Start development server
npm run dev
# Build library
npm run build:lib
# Build example
npm run build🧪 测试
快速测试
- 构建库:
npm run build:lib- 打开测试页面:
test-videojs.html- 基础功能测试example-usage.html- 完整使用示例
验证 VideoJS 可用性
在浏览器控制台中运行:
console.log('VideoJS available:', typeof window.videojs !== 'undefined');如果返回 true,说明 VideoJS 已正确加载。
License
MIT