| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641 |
- <template>
- <div class="page-container">
- <div class="page-header">
- <span class="title">Cloudflare Stream 播放</span>
- </div>
- <!-- 配置区域 -->
- <div class="config-section">
- <el-form label-width="120px">
- <el-form-item label="Video ID">
- <el-input v-model="cfConfig.videoId" placeholder="Cloudflare Stream Video ID" style="width: 400px" />
- </el-form-item>
- <el-form-item label="自定义域名">
- <el-input
- v-model="cfConfig.customerDomain"
- placeholder="customer-xxx.cloudflarestream.com"
- style="width: 400px"
- />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="playCloudflare">播放</el-button>
- <el-button @click="generateCfUrl">生成地址</el-button>
- </el-form-item>
- <el-form-item v-if="cfGeneratedUrl" label="生成的地址">
- <el-input :value="cfGeneratedUrl" readonly style="width: 600px">
- <template #append>
- <el-button @click="copyUrl(cfGeneratedUrl)">复制</el-button>
- </template>
- </el-input>
- </el-form-item>
- </el-form>
- </div>
- <!-- 播放器和PTZ控制区域 -->
- <div class="player-ptz-container">
- <!-- 播放器区域 -->
- <div class="player-section">
- <div v-if="!currentSrc && !currentVideoId" class="player-placeholder">
- <el-icon :size="60" color="#ddd">
- <VideoPlay />
- </el-icon>
- <p>请输入 Video ID 并点击播放</p>
- </div>
- <VideoPlayer
- v-else
- ref="playerRef"
- :player-type="currentPlayerType"
- :video-id="currentVideoId"
- :customer-domain="cfConfig.customerDomain"
- :src="currentSrc"
- :use-iframe="useIframe"
- :autoplay="playConfig.autoplay"
- :muted="playConfig.muted"
- :controls="true"
- @play="onPlay"
- @pause="onPause"
- @error="onError"
- @loadedmetadata="onLoaded"
- />
- </div>
- <!-- PTZ 云台控制 -->
- <div class="ptz-panel">
- <div class="ptz-header">
- <span>PTZ 云台控制</span>
- </div>
- <!-- PTZ 方向控制 九宫格 -->
- <div class="ptz-controls">
- <div class="ptz-btn" @mousedown="handlePTZ('UP_LEFT')" @mouseup="handlePTZStop" @mouseleave="handlePTZStop">
- <el-icon>
- <TopLeft />
- </el-icon>
- </div>
- <div class="ptz-btn" @mousedown="handlePTZ('UP')" @mouseup="handlePTZStop" @mouseleave="handlePTZStop">
- <el-icon>
- <Top />
- </el-icon>
- </div>
- <div class="ptz-btn" @mousedown="handlePTZ('UP_RIGHT')" @mouseup="handlePTZStop" @mouseleave="handlePTZStop">
- <el-icon>
- <TopRight />
- </el-icon>
- </div>
- <div class="ptz-btn" @mousedown="handlePTZ('LEFT')" @mouseup="handlePTZStop" @mouseleave="handlePTZStop">
- <el-icon>
- <Back />
- </el-icon>
- </div>
- <div class="ptz-btn ptz-center" @click="handlePTZStop">
- <el-icon>
- <Refresh />
- </el-icon>
- </div>
- <div class="ptz-btn" @mousedown="handlePTZ('RIGHT')" @mouseup="handlePTZStop" @mouseleave="handlePTZStop">
- <el-icon>
- <Right />
- </el-icon>
- </div>
- <div class="ptz-btn" @mousedown="handlePTZ('DOWN_LEFT')" @mouseup="handlePTZStop" @mouseleave="handlePTZStop">
- <el-icon>
- <BottomLeft />
- </el-icon>
- </div>
- <div class="ptz-btn" @mousedown="handlePTZ('DOWN')" @mouseup="handlePTZStop" @mouseleave="handlePTZStop">
- <el-icon>
- <Bottom />
- </el-icon>
- </div>
- <div
- class="ptz-btn"
- @mousedown="handlePTZ('DOWN_RIGHT')"
- @mouseup="handlePTZStop"
- @mouseleave="handlePTZStop"
- >
- <el-icon>
- <BottomRight />
- </el-icon>
- </div>
- </div>
- <!-- 速度控制 -->
- <div class="speed-control">
- <div class="control-label">
- <span>速度: {{ ptzSpeed }}</span>
- </div>
- <el-slider v-model="ptzSpeed" :min="10" :max="100" :step="10" :show-tooltip="true" />
- </div>
- <!-- 缩放控制 -->
- <div class="zoom-controls">
- <div class="zoom-header">
- <el-icon>
- <ZoomOut />
- </el-icon>
- <span>缩放</span>
- <el-icon>
- <ZoomIn />
- </el-icon>
- </div>
- <el-slider
- v-model="zoomValue"
- :min="-100"
- :max="100"
- :step="10"
- :show-tooltip="true"
- :format-tooltip="formatZoomTooltip"
- @input="handleZoomChange"
- @change="handleZoomRelease"
- />
- </div>
- </div>
- </div>
- <!-- 播放控制 -->
- <div class="control-section">
- <el-space wrap>
- <el-button type="primary" @click="handlePlay">播放</el-button>
- <el-button @click="handlePause">暂停</el-button>
- <el-button type="danger" @click="handleStop">停止</el-button>
- <el-button @click="handleScreenshot">截图</el-button>
- <el-button @click="handleFullscreen">全屏</el-button>
- <el-divider direction="vertical" />
- <el-switch v-model="playConfig.muted" active-text="静音" inactive-text="有声" />
- <el-switch v-model="playConfig.autoplay" active-text="自动播放" inactive-text="手动" />
- </el-space>
- </div>
- <!-- 当前状态 -->
- <!-- <div class="status-section">
- <el-descriptions title="当前状态" :column="3" border>
- <el-descriptions-item label="播放器类型">{{ currentPlayerType }}</el-descriptions-item>
- <el-descriptions-item label="iframe 模式">{{ useIframe ? '是' : '否' }}</el-descriptions-item>
- <el-descriptions-item label="Video ID">{{ currentVideoId || '-' }}</el-descriptions-item>
- <el-descriptions-item label="视频地址" :span="3">
- <el-text truncated style="max-width: 800px">{{ currentSrc || '-' }}</el-text>
- </el-descriptions-item>
- </el-descriptions>
- </div> -->
- <!-- 日志区域 -->
- <div class="log-section">
- <div class="log-header">
- <h4>事件日志</h4>
- <el-button size="small" @click="logs = []">清空</el-button>
- </div>
- <div class="log-content">
- <div v-for="(log, index) in logs" :key="index" class="log-item" :class="log.type">
- <span class="time">{{ log.time }}</span>
- <span class="message">{{ log.message }}</span>
- </div>
- <div v-if="logs.length === 0" class="log-empty">暂无日志</div>
- </div>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { ref, reactive } from 'vue'
- import { ElMessage } from 'element-plus'
- import {
- VideoPlay,
- Top,
- Bottom,
- Back,
- Right,
- TopLeft,
- TopRight,
- BottomLeft,
- BottomRight,
- Refresh,
- ZoomIn,
- ZoomOut
- } from '@element-plus/icons-vue'
- import VideoPlayer from '@/components/VideoPlayer.vue'
- import { startPTZ, stopPTZ, PTZ_DIRECTIONS, startZoom, stopZoom, PTZ_ZOOM_DIRECTIONS } from '@/api/ptz'
- const playerRef = ref<InstanceType<typeof VideoPlayer>>()
- // Cloudflare Stream 配置
- const cfConfig = reactive({
- videoId: '3c1ae1949e76f200feef94b8f7d093ca',
- customerDomain: 'customer-pj89kn2ke2tcuh19.cloudflarestream.com'
- })
- const cfGeneratedUrl = ref('')
- // 播放配置
- const playConfig = reactive({
- autoplay: false,
- muted: true
- })
- // PTZ 配置
- const ptzConfig = reactive({
- host: '192.168.0.64',
- username: 'admin',
- password: 'Wxc767718929'
- })
- // PTZ 速度和缩放
- const ptzSpeed = ref(50)
- const zoomValue = ref(0)
- // 当前播放状态
- const currentSrc = ref('')
- const currentVideoId = ref('')
- const currentPlayerType = ref<'hls' | 'native' | 'cloudflare'>('hls')
- const useIframe = ref(false)
- // 日志
- interface LogItem {
- time: string
- type: 'info' | 'success' | 'error'
- message: string
- }
- const logs = ref<LogItem[]>([])
- function addLog(message: string, type: LogItem['type'] = 'info') {
- const time = new Date().toLocaleTimeString()
- logs.value.unshift({ time, type, message })
- if (logs.value.length > 100) {
- logs.value.pop()
- }
- }
- // 播放 Cloudflare Stream
- function playCloudflare() {
- if (!cfConfig.videoId) {
- ElMessage.warning('请输入 Video ID')
- return
- }
- currentVideoId.value = cfConfig.videoId
- useIframe.value = true
- currentSrc.value = ''
- currentPlayerType.value = 'cloudflare'
- addLog(`播放 Cloudflare Stream: ${cfConfig.videoId} (iframe)`, 'success')
- }
- // 生成 Cloudflare URL
- function generateCfUrl() {
- if (!cfConfig.videoId) {
- ElMessage.warning('请输入 Video ID')
- return
- }
- const domain = cfConfig.customerDomain || 'customer-xxx.cloudflarestream.com'
- cfGeneratedUrl.value = `https://${domain}/${cfConfig.videoId}/iframe`
- }
- // 复制 URL
- function copyUrl(url: string) {
- navigator.clipboard.writeText(url)
- ElMessage.success('已复制到剪贴板')
- }
- // 播放控制
- function handlePlay() {
- playerRef.value?.play()
- addLog('播放', 'info')
- }
- function handlePause() {
- playerRef.value?.pause()
- addLog('暂停', 'info')
- }
- function handleStop() {
- playerRef.value?.stop()
- addLog('停止', 'info')
- }
- function handleScreenshot() {
- playerRef.value?.screenshot()
- addLog('截图', 'info')
- }
- function handleFullscreen() {
- playerRef.value?.fullscreen()
- addLog('全屏', 'info')
- }
- // 事件处理
- function onPlay() {
- addLog('视频开始播放', 'success')
- }
- function onPause() {
- addLog('视频已暂停', 'info')
- }
- function onLoaded() {
- addLog('视频加载完成', 'success')
- }
- function onError(error: any) {
- addLog(`播放错误: ${JSON.stringify(error)}`, 'error')
- }
- // PTZ 控制
- async function handlePTZ(direction: keyof typeof PTZ_DIRECTIONS) {
- if (!ptzConfig.host || !ptzConfig.username || !ptzConfig.password) {
- ElMessage.warning('请先配置摄像头信息')
- return
- }
- const result = await startPTZ(
- {
- host: ptzConfig.host,
- username: ptzConfig.username,
- password: ptzConfig.password
- },
- direction,
- ptzSpeed.value
- )
- if (result.success) {
- addLog(`PTZ 移动: ${direction} (速度: ${ptzSpeed.value})`, 'info')
- } else {
- addLog(`PTZ 控制失败: ${result.error}`, 'error')
- }
- }
- async function handlePTZStop() {
- if (!ptzConfig.host) return
- const result = await stopPTZ({
- host: ptzConfig.host,
- username: ptzConfig.username,
- password: ptzConfig.password
- })
- if (!result.success) {
- addLog(`PTZ 停止失败: ${result.error}`, 'error')
- }
- }
- // 缩放滑块控制
- function formatZoomTooltip(val: number) {
- if (val === 0) return '停止'
- return val > 0 ? `放大 ${val}` : `缩小 ${Math.abs(val)}`
- }
- async function handleZoomChange(val: number) {
- if (!ptzConfig.host || !ptzConfig.username || !ptzConfig.password) return
- if (val === 0) {
- await stopZoom({
- host: ptzConfig.host,
- username: ptzConfig.username,
- password: ptzConfig.password
- })
- return
- }
- const direction = val > 0 ? 'IN' : 'OUT'
- const speed = Math.abs(val)
- await startZoom(
- {
- host: ptzConfig.host,
- username: ptzConfig.username,
- password: ptzConfig.password
- },
- direction,
- speed
- )
- }
- async function handleZoomRelease() {
- // 松开滑块时回到中间并停止
- zoomValue.value = 0
- if (!ptzConfig.host) return
- await stopZoom({
- host: ptzConfig.host,
- username: ptzConfig.username,
- password: ptzConfig.password
- })
- addLog('缩放停止', 'info')
- }
- </script>
- <style lang="scss" scoped>
- .page-container {
- }
- .page-header {
- display: flex;
- align-items: center;
- margin-bottom: 20px;
- padding: 15px 20px;
- background-color: var(--bg-container);
- border-radius: var(--radius-base);
- color: var(--text-primary);
- .title {
- font-size: 18px;
- font-weight: 600;
- }
- }
- .config-section {
- margin-bottom: 20px;
- padding: 20px;
- background-color: var(--bg-container);
- border-radius: var(--radius-base);
- }
- .player-ptz-container {
- display: flex;
- gap: 20px;
- margin-bottom: 20px;
- }
- .player-section {
- flex: 1;
- height: 500px;
- border-radius: var(--radius-base);
- overflow: hidden;
- background-color: #000;
- .player-placeholder {
- height: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- color: var(--text-secondary);
- p {
- margin-top: 15px;
- font-size: 14px;
- }
- }
- }
- .ptz-panel {
- width: 200px;
- background-color: var(--bg-container);
- border-radius: var(--radius-base);
- padding: 15px;
- .ptz-header {
- font-size: 14px;
- font-weight: 600;
- color: var(--text-primary);
- margin-bottom: 15px;
- padding-bottom: 10px;
- border-bottom: 1px solid var(--border-color);
- }
- .ptz-controls {
- display: grid;
- grid-template-columns: repeat(3, 1fr);
- gap: 8px;
- }
- .ptz-btn {
- aspect-ratio: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- background-color: var(--bg-hover);
- border: 1px solid var(--border-color);
- border-radius: var(--radius-sm);
- cursor: pointer;
- transition: all 0.2s;
- color: var(--text-regular);
- &:hover {
- background-color: var(--color-primary-light-9);
- border-color: var(--color-primary);
- color: var(--color-primary);
- }
- &:active {
- background-color: var(--color-primary);
- color: #fff;
- }
- .el-icon {
- font-size: 20px;
- }
- }
- .ptz-center {
- background-color: var(--bg-page);
- &:hover {
- background-color: var(--color-primary-light-9);
- }
- }
- .speed-control {
- margin-top: 15px;
- padding-top: 15px;
- border-top: 1px solid var(--border-color);
- .control-label {
- font-size: 12px;
- color: var(--text-secondary);
- margin-bottom: 8px;
- }
- }
- .zoom-controls {
- margin-top: 15px;
- padding-top: 15px;
- border-top: 1px solid var(--border-color);
- .zoom-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- font-size: 12px;
- color: var(--text-secondary);
- margin-bottom: 8px;
- span {
- flex: 1;
- text-align: center;
- }
- }
- }
- }
- .control-section {
- padding: 15px 20px;
- background-color: var(--bg-container);
- border-radius: var(--radius-base);
- margin-bottom: 20px;
- }
- .status-section {
- margin-bottom: 20px;
- padding: 15px 20px;
- background-color: var(--bg-container);
- border-radius: var(--radius-base);
- }
- .log-section {
- padding: 15px 20px;
- background-color: var(--bg-container);
- border-radius: var(--radius-base);
- .log-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 10px;
- h4 {
- font-size: 14px;
- margin: 0;
- color: var(--text-primary);
- }
- }
- .log-content {
- max-height: 200px;
- overflow-y: auto;
- background-color: var(--bg-hover);
- border-radius: var(--radius-sm);
- padding: 10px;
- }
- .log-item {
- font-size: 12px;
- padding: 4px 0;
- border-bottom: 1px solid var(--border-color-light);
- color: var(--text-regular);
- &:last-child {
- border-bottom: none;
- }
- .time {
- color: var(--text-secondary);
- margin-right: 10px;
- }
- &.success .message {
- color: var(--color-success);
- }
- &.error .message {
- color: var(--color-danger);
- }
- }
- .log-empty {
- text-align: center;
- color: var(--text-secondary);
- font-size: 12px;
- padding: 20px 0;
- }
- }
- </style>
|