Skip to content

Commit

Permalink
feat: chooseVideo 读取视频信息
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyucoding committed Mar 5, 2019
1 parent ed1f55c commit 72ea53c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/platforms/h5/service/api/media/choose-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const _createInput = function (options) {
'width': 0,
'height': 0
})
// inputEl.style = 'position: absolute;visibility: hidden;z-index: -999;width: 0;height: 0;'
inputEl.accept = 'image/*'
if (options.count > 1) {
inputEl.multiple = 'multiple'
Expand Down
18 changes: 14 additions & 4 deletions src/platforms/h5/service/api/media/choose-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const _createInput = function (options) {
'width': 0,
'height': 0
})
// inputEl.style = 'position: absolute;visibility: hidden;z-index: -999;width: 0;height: 0;'
inputEl.accept = 'video/*'
// 经过测试,仅能限制只通过相机拍摄,不能限制只允许从相册选择。
if (options.sourceType.length === 1 && options.sourceType[0] === 'camera') {
Expand All @@ -43,12 +42,23 @@ export function chooseVideo ({
const file = event.target.files[0]
const filePath = fileToUrl(file)

invoke(callbackId, {
let callbackResult = {
errMsg: 'chooseVideo:ok',
tempFilePath: filePath,
size: file.size
})
size: file.size,
duration: 0,
width: 0,
height: 0
}

const video = document.createElement('video')
video.addEventListener('loadedmetadata', function () {
callbackResult.duration = video.duration || 0
callbackResult.width = video.videoWidth || 0
callbackResult.height = video.videoHeight || 0
invoke(callbackId, callbackResult)
})
video.src = filePath
// TODO 用户取消选择时,触发 fail,目前尚未找到合适的方法。
})

Expand Down

0 comments on commit 72ea53c

Please sign in to comment.