智能照明系统APP-本地串口
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.
 
 
 
 
 
 
LightingSystemApp-serial/.svn/pristine/ba/ba5ac481c685b01c81c70f12085...

97 lines
2.3 KiB

import {
TEMP_PATH
} from '../constants'
import {
invoke
} from '../../bridge'
const invokeChooseVideo = function (callbackId, type, tempFilePath = '') {
const callbackResult = {
errMsg: `chooseVideo:${type}`,
tempFilePath: tempFilePath,
duration: 0,
size: 0,
height: 0,
width: 0
}
if (type !== 'ok') {
invoke(callbackId, callbackResult)
return
}
plus.io.getVideoInfo({
filePath: tempFilePath,
success (videoInfo) {
callbackResult.size = videoInfo.size
callbackResult.duration = videoInfo.duration
callbackResult.width = videoInfo.width
callbackResult.height = videoInfo.height
invoke(callbackId, callbackResult)
},
fail () {
invoke(callbackId, callbackResult)
},
complete () {
invoke(callbackId, callbackResult)
}
})
}
const openCamera = function (callbackId, maxDuration, cameraIndex) {
const camera = plus.camera.getCamera()
camera.startVideoCapture(e => invokeChooseVideo(callbackId, 'ok', e), e => invokeChooseVideo(
callbackId, 'fail'), {
index: cameraIndex,
videoMaximumDuration: maxDuration,
filename: TEMP_PATH + '/camera/'
})
}
const openAlbum = function (callbackId) {
plus.gallery.pick(e => {
invokeChooseVideo(callbackId, 'ok', e)
}, e => invokeChooseVideo(callbackId, 'fail'), {
filter: 'video',
system: false,
filename: TEMP_PATH + '/gallery/'
})
}
export function chooseVideo ({
sourceType = ['album', 'camera'],
maxDuration = 60,
camera = 'back'
} = {}, callbackId) {
let fallback = true
const cameraIndex = (camera === 'front') ? 2 : 1
if (sourceType.length === 1) {
if (sourceType[0] === 'album') {
fallback = false
openAlbum(callbackId)
} else if (sourceType[0] === 'camera') {
fallback = false
openCamera(callbackId, maxDuration, cameraIndex)
}
}
if (fallback) {
plus.nativeUI.actionSheet({
cancel: '取消',
buttons: [{
title: '拍摄'
}, {
title: '从手机相册选择'
}]
}, e => {
switch (e.index) {
case 0:
invokeChooseVideo(callbackId, 'fail')
break
case 1:
openCamera(callbackId, maxDuration, cameraIndex)
break
case 2:
openAlbum(callbackId)
break
}
})
}
}