|
@@ -0,0 +1,357 @@
|
|
|
|
|
+<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 label="播放方式">
|
|
|
|
|
+ <el-select v-model="cfConfig.playMode" style="width: 200px">
|
|
|
|
|
+ <el-option label="iframe 嵌入" value="iframe" />
|
|
|
|
|
+ <el-option label="HLS 播放" value="hls" />
|
|
|
|
|
+ </el-select>
|
|
|
|
|
+ </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>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 播放器区域 -->
|
|
|
|
|
+ <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>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 播放控制 -->
|
|
|
|
|
+ <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 } from '@element-plus/icons-vue'
|
|
|
|
|
+import VideoPlayer from '@/components/VideoPlayer.vue'
|
|
|
|
|
+
|
|
|
|
|
+const playerRef = ref<InstanceType<typeof VideoPlayer>>()
|
|
|
|
|
+
|
|
|
|
|
+// Cloudflare Stream 配置
|
|
|
|
|
+const cfConfig = reactive({
|
|
|
|
|
+ videoId: '3c1ae1949e76f200feef94b8f7d093ca',
|
|
|
|
|
+ customerDomain: 'customer-pj89kn2ke2tcuh19.cloudflarestream.com',
|
|
|
|
|
+ playMode: 'iframe' as 'iframe' | 'hls'
|
|
|
|
|
+})
|
|
|
|
|
+const cfGeneratedUrl = ref('')
|
|
|
|
|
+
|
|
|
|
|
+// 播放配置
|
|
|
|
|
+const playConfig = reactive({
|
|
|
|
|
+ autoplay: false,
|
|
|
|
|
+ muted: true
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+// 当前播放状态
|
|
|
|
|
+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 = cfConfig.playMode === 'iframe'
|
|
|
|
|
+
|
|
|
|
|
+ if (cfConfig.playMode === 'hls') {
|
|
|
|
|
+ const domain = cfConfig.customerDomain || 'customer-xxx.cloudflarestream.com'
|
|
|
|
|
+ currentSrc.value = `https://${domain}/${cfConfig.videoId}/manifest/video.m3u8`
|
|
|
|
|
+ currentPlayerType.value = 'hls'
|
|
|
|
|
+ } else {
|
|
|
|
|
+ currentSrc.value = ''
|
|
|
|
|
+ currentPlayerType.value = 'cloudflare'
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ addLog(`播放 Cloudflare Stream: ${cfConfig.videoId} (${cfConfig.playMode})`, 'success')
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 生成 Cloudflare URL
|
|
|
|
|
+function generateCfUrl() {
|
|
|
|
|
+ if (!cfConfig.videoId) {
|
|
|
|
|
+ ElMessage.warning('请输入 Video ID')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ const domain = cfConfig.customerDomain || 'customer-xxx.cloudflarestream.com'
|
|
|
|
|
+ if (cfConfig.playMode === 'iframe') {
|
|
|
|
|
+ cfGeneratedUrl.value = `https://${domain}/${cfConfig.videoId}/iframe`
|
|
|
|
|
+ } else {
|
|
|
|
|
+ cfGeneratedUrl.value = `https://${domain}/${cfConfig.videoId}/manifest/video.m3u8`
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 复制 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')
|
|
|
|
|
+}
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
|
+.page-container {
|
|
|
|
|
+ min-height: 100vh;
|
|
|
|
|
+ background-color: #f5f7fa;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.page-header {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ margin-bottom: 20px;
|
|
|
|
|
+ padding: 15px 20px;
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+
|
|
|
|
|
+ .title {
|
|
|
|
|
+ font-size: 18px;
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.config-section {
|
|
|
|
|
+ margin-bottom: 20px;
|
|
|
|
|
+ padding: 20px;
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.player-section {
|
|
|
|
|
+ height: 500px;
|
|
|
|
|
+ margin-bottom: 20px;
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+ overflow: hidden;
|
|
|
|
|
+ background-color: #000;
|
|
|
|
|
+
|
|
|
|
|
+ .player-placeholder {
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ flex-direction: column;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+ color: #999;
|
|
|
|
|
+
|
|
|
|
|
+ p {
|
|
|
|
|
+ margin-top: 15px;
|
|
|
|
|
+ font-size: 14px;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.control-section {
|
|
|
|
|
+ padding: 15px 20px;
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+ margin-bottom: 20px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.status-section {
|
|
|
|
|
+ margin-bottom: 20px;
|
|
|
|
|
+ padding: 15px 20px;
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.log-section {
|
|
|
|
|
+ padding: 15px 20px;
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+
|
|
|
|
|
+ .log-header {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ justify-content: space-between;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ margin-bottom: 10px;
|
|
|
|
|
+
|
|
|
|
|
+ h4 {
|
|
|
|
|
+ font-size: 14px;
|
|
|
|
|
+ margin: 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .log-content {
|
|
|
|
|
+ max-height: 200px;
|
|
|
|
|
+ overflow-y: auto;
|
|
|
|
|
+ background-color: #fafafa;
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+ padding: 10px;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .log-item {
|
|
|
|
|
+ font-size: 12px;
|
|
|
|
|
+ padding: 4px 0;
|
|
|
|
|
+ border-bottom: 1px solid #eee;
|
|
|
|
|
+
|
|
|
|
|
+ &:last-child {
|
|
|
|
|
+ border-bottom: none;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .time {
|
|
|
|
|
+ color: #999;
|
|
|
|
|
+ margin-right: 10px;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ &.success .message {
|
|
|
|
|
+ color: #67c23a;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ &.error .message {
|
|
|
|
|
+ color: #f56c6c;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .log-empty {
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ color: #999;
|
|
|
|
|
+ font-size: 12px;
|
|
|
|
|
+ padding: 20px 0;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+</style>
|