/** * 视频:先下载远程地址到本地,再用系统默认应用打开;本地路径直接打开。 */ function openLocalVideoPath(filePath) { if (!filePath) return // #ifdef APP-PLUS try { if (typeof plus !== 'undefined' && plus.runtime && typeof plus.runtime.openFile === 'function') { plus.runtime.openFile(filePath, () => { uni.openDocument({ filePath, fail: () => { uni.showToast({ title: '无法打开视频', icon: 'none' }) } }) }) return } } catch (e) { // fall through } // #endif uni.openDocument({ filePath, fail: () => { uni.showToast({ title: '无法打开视频', icon: 'none' }) } }) } /** * @param {string} pathOrUrl - 本地临时路径或 http(s) 地址 */ export function openVideoWithSystemPlayer(pathOrUrl) { if (!pathOrUrl) return const s = String(pathOrUrl).trim() if (/^https?:\/\//i.test(s)) { uni.showLoading({ title: '下载中', mask: true }) uni.downloadFile({ url: s, success: (res) => { if (res.statusCode === 200 && res.tempFilePath) { openLocalVideoPath(res.tempFilePath) } else { uni.showToast({ title: '下载失败', icon: 'none' }) } }, fail: () => { uni.showToast({ title: '下载失败', icon: 'none' }) }, complete: () => { uni.hideLoading() } }) return } openLocalVideoPath(s) }