You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.5 KiB
77 lines
1.5 KiB
import {
|
|
TEMP_PATH
|
|
} from '../constants'
|
|
|
|
import {
|
|
publish
|
|
} from '../../bridge'
|
|
|
|
let recorder
|
|
let recordTimeout
|
|
|
|
const publishRecorderStateChange = (state, res = {}) => {
|
|
publish('onRecorderStateChange', Object.assign({
|
|
state
|
|
}, res))
|
|
}
|
|
|
|
const Recorder = {
|
|
start ({
|
|
duration = 60000,
|
|
sampleRate,
|
|
numberOfChannels,
|
|
encodeBitRate,
|
|
format = 'mp3',
|
|
frameSize,
|
|
audioSource = 'auto'
|
|
}, callbackId) {
|
|
if (recorder) {
|
|
return publishRecorderStateChange('start')
|
|
}
|
|
recorder = plus.audio.getRecorder()
|
|
recorder.record({
|
|
format,
|
|
samplerate: sampleRate,
|
|
filename: TEMP_PATH + '/recorder/'
|
|
}, res => publishRecorderStateChange('stop', {
|
|
tempFilePath: res
|
|
}), err => publishRecorderStateChange('error', {
|
|
errMsg: err.message
|
|
}))
|
|
recordTimeout = setTimeout(() => {
|
|
Recorder.stop()
|
|
}, duration)
|
|
publishRecorderStateChange('start')
|
|
},
|
|
stop () {
|
|
if (recorder) {
|
|
recorder.stop()
|
|
recorder = false
|
|
recordTimeout && clearTimeout(recordTimeout)
|
|
}
|
|
},
|
|
pause () {
|
|
if (recorder) {
|
|
publishRecorderStateChange('error', {
|
|
errMsg: '暂不支持录音pause操作'
|
|
})
|
|
}
|
|
},
|
|
resume () {
|
|
if (recorder) {
|
|
publishRecorderStateChange('error', {
|
|
errMsg: '暂不支持录音resume操作'
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
export function operateRecorder ({
|
|
operationType,
|
|
...args
|
|
}, callbackId) {
|
|
Recorder[operationType](args)
|
|
return {
|
|
errMsg: 'operateRecorder:ok'
|
|
}
|
|
}
|
|
|