|
|
@ -113,6 +113,47 @@ export const takePhotoWithWaterMark = async ({ |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 将文件从公共目录复制到应用私有目录(解决 Android 11+ 分区存储导致的 EACCES 权限问题)
|
|
|
|
|
|
const copyFileToAppDir = (sourcePath) => { |
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
if (!window.cordova?.file?.dataDirectory) { |
|
|
|
|
|
reject(new Error('cordova.file.dataDirectory 不可用')) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
window.resolveLocalFileSystemURL( |
|
|
|
|
|
sourcePath, |
|
|
|
|
|
(fileEntry) => { |
|
|
|
|
|
window.resolveLocalFileSystemURL( |
|
|
|
|
|
window.cordova.file.dataDirectory, |
|
|
|
|
|
(dataDirEntry) => { |
|
|
|
|
|
const fileName = fileEntry.name |
|
|
|
|
|
fileEntry.copyTo( |
|
|
|
|
|
dataDirEntry, |
|
|
|
|
|
fileName, |
|
|
|
|
|
(newFileEntry) => { |
|
|
|
|
|
console.log('[w6sMedia] 文件已复制到应用私有目录:', newFileEntry.fullPath) |
|
|
|
|
|
resolve(newFileEntry.fullPath) |
|
|
|
|
|
}, |
|
|
|
|
|
(copyErr) => { |
|
|
|
|
|
console.error('[w6sMedia] 复制文件失败:', copyErr) |
|
|
|
|
|
reject(copyErr) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
}, |
|
|
|
|
|
(dirErr) => { |
|
|
|
|
|
console.error('[w6sMedia] 获取应用私有目录失败:', dirErr) |
|
|
|
|
|
reject(dirErr) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
}, |
|
|
|
|
|
(fileErr) => { |
|
|
|
|
|
console.error('[w6sMedia] 解析源文件失败:', fileErr, 'sourcePath:', sourcePath) |
|
|
|
|
|
reject(fileErr) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 录制视频(使用 Cordova 原生 Media Capture API)
|
|
|
// 录制视频(使用 Cordova 原生 Media Capture API)
|
|
|
export const startVideoRecorder = async ({ |
|
|
export const startVideoRecorder = async ({ |
|
|
duration = 60, |
|
|
duration = 60, |
|
|
@ -130,17 +171,29 @@ export const startVideoRecorder = async ({ |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
navigator.device.capture.captureVideo( |
|
|
navigator.device.capture.captureVideo( |
|
|
(mediaFiles) => { |
|
|
async (mediaFiles) => { |
|
|
console.log('[w6sMedia] captureVideo success, mediaFiles:', mediaFiles) |
|
|
console.log('[w6sMedia] captureVideo success, mediaFiles:', mediaFiles) |
|
|
if (mediaFiles && mediaFiles.length > 0) { |
|
|
if (mediaFiles && mediaFiles.length > 0) { |
|
|
const file = mediaFiles[0] |
|
|
const file = mediaFiles[0] |
|
|
console.log('[w6sMedia] 视频文件: fullPath=', file.fullPath, 'name=', file.name, 'size=', file.size, 'type=', file.type) |
|
|
console.log('[w6sMedia] 视频文件: fullPath=', file.fullPath, 'name=', file.name, 'size=', file.size, 'type=', file.type) |
|
|
resolve({ |
|
|
try { |
|
|
video_path: file.fullPath, |
|
|
const appDirPath = await copyFileToAppDir(file.fullPath) |
|
|
name: file.name, |
|
|
console.log('[w6sMedia] 视频已复制到应用私有目录:', appDirPath) |
|
|
size: file.size, |
|
|
resolve({ |
|
|
type: file.type || 'video/mp4', |
|
|
video_path: appDirPath, |
|
|
}) |
|
|
name: file.name, |
|
|
|
|
|
size: file.size, |
|
|
|
|
|
type: file.type || 'video/mp4', |
|
|
|
|
|
}) |
|
|
|
|
|
} catch (copyErr) { |
|
|
|
|
|
console.warn('[w6sMedia] 复制视频失败,尝试使用原路径:', copyErr) |
|
|
|
|
|
resolve({ |
|
|
|
|
|
video_path: file.fullPath, |
|
|
|
|
|
name: file.name, |
|
|
|
|
|
size: file.size, |
|
|
|
|
|
type: file.type || 'video/mp4', |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
reject(new Error('录制未生成视频文件')) |
|
|
reject(new Error('录制未生成视频文件')) |
|
|
} |
|
|
} |
|
|
|