mirror of
https://github.com/HuLaSpark/HuLa.git
synced 2026-09-24 23:11:59 +08:00
fix(video): 🐛 fix video not playing problem
This commit is contained in:
+2
-2
@@ -15,9 +15,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.6.13</string>
|
||||
<string>3.0.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2.6.13</string>
|
||||
<string>3.0.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAccessibilityUsageDescription</key>
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -286,12 +286,7 @@ const handleOpenVideoViewer = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 使用本地绝对路径打开视频
|
||||
const localPath = await getLocalVideoPath(props.body.url)
|
||||
const resourceDirPath = await resourceDir()
|
||||
const videoUrl = await join(resourceDirPath, localPath)
|
||||
|
||||
await openVideoViewer(videoUrl, [MsgEnum.VIDEO])
|
||||
await openVideoViewer(props.body.url, [MsgEnum.VIDEO])
|
||||
} catch (error) {
|
||||
console.error('打开视频失败:', error)
|
||||
} finally {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { join, resourceDir } from '@tauri-apps/api/path'
|
||||
import { appDataDir, join, resourceDir } from '@tauri-apps/api/path'
|
||||
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
|
||||
import { BaseDirectory, exists } from '@tauri-apps/plugin-fs'
|
||||
import { MsgEnum } from '@/enums'
|
||||
@@ -64,7 +64,6 @@ export const useVideoViewer = () => {
|
||||
|
||||
// 检查视频是否已下载到本地
|
||||
const checkVideoDownloaded = async (url: string) => {
|
||||
if (isMobile()) return false
|
||||
if (!url) return false
|
||||
try {
|
||||
const localPath = await getLocalVideoPath(url)
|
||||
@@ -83,8 +82,9 @@ export const useVideoViewer = () => {
|
||||
const isDownloaded = await checkVideoDownloaded(url)
|
||||
if (isDownloaded) {
|
||||
const localPath = await getLocalVideoPath(url)
|
||||
const resourceDirPath = await resourceDir()
|
||||
return await join(resourceDirPath, localPath)
|
||||
// 使用与下载时一致的基础目录
|
||||
const baseDirPath = isMobile() ? await appDataDir() : await resourceDir()
|
||||
return await join(baseDirPath, localPath)
|
||||
}
|
||||
return url
|
||||
}
|
||||
@@ -156,11 +156,11 @@ export const useVideoViewer = () => {
|
||||
const processedIndex = processedList.findIndex((path) => path === currentVideoPath || path === url)
|
||||
const finalIndex = processedIndex !== -1 ? processedIndex : index
|
||||
|
||||
// 统一使用列表模式,不再区分单视频模式
|
||||
VideoViewerStore.resetVideoListOptimized(processedList, finalIndex)
|
||||
VideoViewerStore.$patch({
|
||||
videoList: [...processedList],
|
||||
currentVideoIndex: finalIndex,
|
||||
isSingleVideoMode: processedList.length <= 1
|
||||
currentVideoIndex: finalIndex
|
||||
})
|
||||
|
||||
// 检查现有窗口
|
||||
|
||||
@@ -13,9 +13,6 @@ export const useVideoViewer = defineStore(
|
||||
// 视频相关变量
|
||||
const videoList = ref<string[]>([])
|
||||
const currentVideoIndex = ref(0)
|
||||
// 单视频模式相关变量
|
||||
const singleVideo = ref('')
|
||||
const isSingleVideoMode = ref(false)
|
||||
|
||||
// 添加一个重置方法,用于设置新的图片列表
|
||||
const resetImageList = (list: string[], originalIndex: number) => {
|
||||
@@ -46,7 +43,6 @@ export const useVideoViewer = defineStore(
|
||||
|
||||
// 用于设置新的视频列表
|
||||
const resetVideoListOptimized = (list: string[], originalIndex: number) => {
|
||||
isSingleVideoMode.value = false
|
||||
const uniqueList: string[] = []
|
||||
const seenUrls = new Set<string>()
|
||||
|
||||
@@ -63,30 +59,17 @@ export const useVideoViewer = defineStore(
|
||||
currentVideoIndex.value = newIndex !== -1 ? newIndex : 0
|
||||
}
|
||||
|
||||
const setSingleVideoOptimized = (url: string) => {
|
||||
singleVideo.value = url
|
||||
isSingleVideoMode.value = true
|
||||
}
|
||||
|
||||
// 更新视频列表中的特定视频路径(用于下载完成后更新为本地路径)
|
||||
const updateVideoPath = (originalUrl: string, newPath: string) => {
|
||||
const index = videoList.value.indexOf(originalUrl)
|
||||
if (index !== -1) {
|
||||
videoList.value[index] = newPath
|
||||
}
|
||||
// 如果当前单视频模式的视频是被更新的视频,也要更新
|
||||
if (singleVideo.value === originalUrl) {
|
||||
singleVideo.value = newPath
|
||||
}
|
||||
}
|
||||
|
||||
// 批量更新视频路径(用于批量处理本地路径)
|
||||
const updateVideoListPaths = (pathMapping: Record<string, string>) => {
|
||||
videoList.value = videoList.value.map((url) => pathMapping[url] || url)
|
||||
// 更新单视频模式的路径
|
||||
if (singleVideo.value && pathMapping[singleVideo.value]) {
|
||||
singleVideo.value = pathMapping[singleVideo.value]
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -99,9 +82,6 @@ export const useVideoViewer = defineStore(
|
||||
videoList,
|
||||
currentVideoIndex,
|
||||
resetVideoListOptimized,
|
||||
singleVideo,
|
||||
isSingleVideoMode,
|
||||
setSingleVideoOptimized,
|
||||
updateVideoPath,
|
||||
updateVideoListPaths
|
||||
}
|
||||
|
||||
@@ -124,15 +124,6 @@
|
||||
|
||||
<n-switch size="small" v-model:value="showText" />
|
||||
</n-flex>
|
||||
|
||||
<span class="w-full h-1px bg-[--line-color]"></span>
|
||||
|
||||
<!-- 临时清除缓存 -->
|
||||
<n-flex align="center" justify="space-between">
|
||||
<span>临时功能: 清除localstorage缓存</span>
|
||||
|
||||
<n-button size="small" secondary type="error" @click="clearLocalstorage">清除缓存</n-button>
|
||||
</n-flex>
|
||||
</n-flex>
|
||||
</n-flex>
|
||||
</n-flex>
|
||||
@@ -173,11 +164,6 @@ const handleTheme = (code: string) => {
|
||||
const setHomeHeight = async () => {
|
||||
invoke('set_height', { height: showMode.value === ShowModeEnum.TEXT ? 505 : 423 })
|
||||
}
|
||||
|
||||
const clearLocalstorage = () => {
|
||||
localStorage.clear()
|
||||
window.$message?.success('清除成功')
|
||||
}
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.item {
|
||||
|
||||
@@ -114,14 +114,9 @@ const tipText = ref('')
|
||||
const videoWidth = ref(0)
|
||||
const videoHeight = ref(0)
|
||||
|
||||
// 当前显示的视频URL
|
||||
// 当前显示的视频URL(统一使用列表模式)
|
||||
const currentVideo = computed(() => {
|
||||
let videoUrl = ''
|
||||
if (videoViewerStore.isSingleVideoMode) {
|
||||
videoUrl = videoViewerStore.singleVideo
|
||||
} else {
|
||||
videoUrl = videoList.value[currentIndex.value]
|
||||
}
|
||||
const videoUrl = videoList.value[currentIndex.value] || ''
|
||||
|
||||
// 如果是本地文件路径,使用 Tauri 的 convertFileSrc 来转换
|
||||
if (videoUrl && !videoUrl.startsWith('http')) {
|
||||
@@ -140,29 +135,29 @@ const videoClass = computed(() => {
|
||||
|
||||
// 是否可以切换到上一个视频
|
||||
const canGoPrevious = computed(() => {
|
||||
if (videoViewerStore.isSingleVideoMode) return false
|
||||
if (videoList.value.length <= 1) return false
|
||||
|
||||
const currentVideoPath = videoList.value[currentIndex.value]
|
||||
if (!currentVideoPath || currentVideoPath.startsWith('http')) {
|
||||
// 网络视频使用原有逻辑
|
||||
// 网络视频:检查是否不是第一个
|
||||
return currentIndex.value > 0
|
||||
}
|
||||
|
||||
// 本地视频总是返回true,具体判断在点击时进行
|
||||
// 本地视频:总是返回true,具体判断在点击时进行
|
||||
return true
|
||||
})
|
||||
|
||||
// 是否可以切换到下一个视频
|
||||
const canGoNext = computed(() => {
|
||||
if (videoViewerStore.isSingleVideoMode) return false
|
||||
if (videoList.value.length <= 1) return false
|
||||
|
||||
const currentVideoPath = videoList.value[currentIndex.value]
|
||||
if (!currentVideoPath || currentVideoPath.startsWith('http')) {
|
||||
// 网络视频使用原有逻辑
|
||||
// 网络视频:检查是否不是最后一个
|
||||
return currentIndex.value < videoList.value.length - 1
|
||||
}
|
||||
|
||||
// 本地视频总是返回true,具体判断在点击时进行
|
||||
// 本地视频:总是返回true,具体判断在点击时进行
|
||||
return true
|
||||
})
|
||||
|
||||
@@ -263,9 +258,6 @@ const onVideoPlay = () => {
|
||||
const previousVideo = async () => {
|
||||
if (!canGoPrevious.value) return
|
||||
|
||||
// 如果是单视频模式,不允许切换
|
||||
if (videoViewerStore.isSingleVideoMode) return
|
||||
|
||||
const currentVideoPath = videoList.value[currentIndex.value]
|
||||
if (!currentVideoPath || currentVideoPath.startsWith('http')) {
|
||||
// 如果是网络视频,使用原有逻辑
|
||||
@@ -311,9 +303,6 @@ const previousVideo = async () => {
|
||||
const nextVideo = async () => {
|
||||
if (!canGoNext.value) return
|
||||
|
||||
// 如果是单视频模式,不允许切换
|
||||
if (videoViewerStore.isSingleVideoMode) return
|
||||
|
||||
const currentVideoPath = videoList.value[currentIndex.value]
|
||||
if (!currentVideoPath || currentVideoPath.startsWith('http')) {
|
||||
// 如果是网络视频,使用原有逻辑
|
||||
@@ -385,16 +374,10 @@ onMounted(async () => {
|
||||
})
|
||||
)
|
||||
|
||||
if (videoViewerStore.isSingleVideoMode) {
|
||||
videoList.value = [videoViewerStore.singleVideo]
|
||||
currentIndex.value = 0
|
||||
} else {
|
||||
// 添加数据有效性验证
|
||||
const validIndex = Math.min(Math.max(videoViewerStore.currentVideoIndex, 0), videoViewerStore.videoList.length - 1)
|
||||
videoList.value = [...videoViewerStore.videoList]
|
||||
currentIndex.value = validIndex
|
||||
console.log('Initial index:', validIndex)
|
||||
}
|
||||
// 统一使用列表模式初始化
|
||||
const validIndex = Math.min(Math.max(videoViewerStore.currentVideoIndex, 0), videoViewerStore.videoList.length - 1)
|
||||
videoList.value = [...videoViewerStore.videoList]
|
||||
currentIndex.value = validIndex
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user