utils.uts 1.25 KB
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']