hookehuyr

refactor(useVideoPlayer): 添加注释并重新组织视频播放器逻辑

为视频播放器逻辑添加清晰的注释标记
重新组织代码结构使其更易读
......@@ -44,11 +44,13 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
return (props.videoUrl || "").trim();
});
// 3. HLS 支持判断
const isM3U8 = computed(() => {
const url = videoUrlValue.value.toLowerCase();
return url.includes('.m3u8');
});
// 4. 视频类型判断
const getVideoMimeType = (url) => {
const urlText = (url || "").toLowerCase();
if (urlText.includes(".m3u8")) return "application/x-mpegURL";
......@@ -57,6 +59,7 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
return "";
};
// 5. 视频源配置
const videoSources = computed(() => {
const type = getVideoMimeType(videoUrlValue.value);
if (type) {
......@@ -65,7 +68,7 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
return [{ src: videoUrlValue.value }];
});
// 3. 错误处理逻辑
// 6. 错误处理逻辑
const formatBytes = (bytes) => {
const size = Number(bytes) || 0;
if (!size) return "";
......@@ -156,6 +159,7 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
}
};
// 7. 错误处理逻辑
const handleError = (code, message = '') => {
showErrorOverlay.value = true;
switch (code) {
......@@ -281,6 +285,7 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
...props.options,
}));
// 8. Video.js 挂载处理
const handleVideoJsMounted = (payload) => {
state.value = payload.state;
player.value = payload.player;
......