utils.uts
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { RecorderManagerOnStopResult } from '../interface.uts';
import File from 'java.io.File';
import UUID from 'java.util.UUID';
export type RecorderState = 'pause' | 'resume' | 'start' | 'stop' | 'error' | 'frameRecorded' | 'interruptionBegin' | 'interruptionEnd'
export interface StateChangeRes extends RecorderManagerOnStopResult {
errMsg ?: string
frameBuffer ?: ArrayBuffer
isLastFrame ?: boolean
}
export function onRecorderStateChange(state : RecorderState, res ?: StateChangeRes) : void {
}
export function createFile( format : string, saveDir ?: string | null) : string {
var dirPath : string
if (saveDir != null && saveDir!.length > 0) {
dirPath = saveDir!
} else {
let context = UTSAndroid.getAppContext()
var parentPath = UTSAndroid.getAppCachePath()
if (context != null) {
let filesDir = context.getExternalFilesDir(null)
if (filesDir != null) {
parentPath = filesDir.path
}
}
dirPath = parentPath!
}
const fileDir = `${dirPath}/records`
let dir = new File(fileDir)
if (!dir.exists()) {
dir.mkdirs()
}
const random = UUID.randomUUID().toString().replace(/-/g, '').substring(0, 8)
const fileName = `${Date.now()}_${random}.${format.toLocaleLowerCase()}`
return `${dir.path}/${fileName}`
}
export const supportFormats = ['aac']