提交 c9b4b6c9 编写于 作者: Q qiang

Merge branch 'dev' into alpha

......@@ -241,7 +241,7 @@ export default {
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序|QQ小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|x|x|2.11.0+|x|x|x|x|
|3.1.10+|3.1.10+|2.11.0+|x|x|x|x|
**OBJECT 参数说明**
......@@ -254,16 +254,16 @@ export default {
**success 返回参数说明**
|参数名 |类型 |说明 |
|:- |:- |:- |
|orientation|string |画面方向 |
|type |string |视频格式 |
|duration |number |视频长度 |
|size |number |视频大小,单位 kB |
|height |number |视频的长,单位 px |
|width |number |视频的宽,单位 px |
|fps |number |视频帧率 |
|bitrate |number |视频码率,单位 kbps|
|参数名 |类型 |说明 |平台差异说明|
|:- |:- |:- ||
|orientation|string |画面方向 |微信小程序|
|type |string |视频格式 |微信小程序|
|duration |number |视频长度 |微信小程序、App、H5|
|size |number |视频大小,单位 kB |微信小程序、App、H5|
|height |number |视频的长,单位 px |微信小程序、App、H5|
|width |number |视频的宽,单位 px |微信小程序、App、H5|
|fps |number |视频帧率 |微信小程序、App|
|bitrate |number |视频码率,单位 kbps|微信小程序|
**res.orientation参数说明**
......@@ -286,7 +286,7 @@ export default {
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序|QQ小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|x|x|2.11.0+|x|x|x|x|
|3.1.10+|x|2.11.0+|x|x|x|x|
App端有很多插件支持视频压缩,详见[插件市场](https://ext.dcloud.net.cn/search?q=%E8%A7%86%E9%A2%91%E5%8E%8B%E7%BC%A9)
......
const eventTypes = {
load: 'load',
close: 'close',
error: 'error',
adClicked: 'adClicked'
}
const eventNames = [
eventTypes.load,
eventTypes.close,
eventTypes.error,
eventTypes.adClicked
]
class AdBase {
constructor (adInstance, options) {
const _callbacks = this._callbacks = {}
eventNames.forEach(item => {
_callbacks[item] = []
const name = item[0].toUpperCase() + item.substr(1)
this[`on${name}`] = function (callback) {
_callbacks[item].push(callback)
}
})
this._preload = options.preload !== undefined ? options.preload : false
this._isLoaded = false
this._isLoading = false
this._adError = ''
this._loadPromiseResolve = null
this._loadPromiseReject = null
this._showPromiseResolve = null
this._showPromiseReject = null
const ad = this._ad = adInstance
ad.onLoad((e) => {
this._isLoaded = true
this._isLoading = false
this._dispatchEvent(eventTypes.load, {})
if (this._loadPromiseResolve != null) {
this._loadPromiseResolve()
this._loadPromiseResolve = null
}
if (this._showPromiseResolve != null) {
this._showPromiseResolve()
this._showPromiseResolve = null
this._showAd()
}
})
ad.onClose((e) => {
this._isLoaded = false
this._isLoading = false
this._dispatchEvent(eventTypes.close, { isEnded: e.isEnded })
if (this._preload === true) {
this._loadAd()
}
})
ad.onError((e) => {
this._isLoading = false
const data = {
code: e.code,
errMsg: e.message
}
this._adError = data
this._dispatchEvent(eventTypes.error, data)
const promiseError = new Error(JSON.stringify(this._adError))
promiseError.code = e.code
promiseError.errMsg = e.message
if (this._loadPromiseReject != null) {
this._loadPromiseReject(promiseError)
this._loadPromiseReject = null
}
if (this._showPromiseReject != null) {
this._showPromiseReject(promiseError)
this._showPromiseReject = null
}
})
ad.onAdClicked && ad.onAdClicked((e) => {
this._dispatchEvent(eventTypes.adClicked, {})
})
}
load () {
return new Promise((resolve, reject) => {
this._loadPromiseResolve = resolve
this._loadPromiseReject = reject
if (this._isLoading) {
return
}
if (this._isLoaded) {
resolve()
} else {
this._loadAd()
}
})
}
show () {
return new Promise((resolve, reject) => {
this._showPromiseResolve = resolve
this._showPromiseReject = reject
if (this._isLoading) {
return
}
if (this._isLoaded) {
this._showAd()
resolve()
} else {
this._loadAd()
}
})
}
destroy () {
this._ad.destroy()
}
getProvider () {
return this._ad.getProvider()
}
_loadAd () {
this._adError = ''
this._isLoaded = false
this._isLoading = true
this._ad.load()
}
_showAd () {
this._ad.show()
}
_dispatchEvent (name, data) {
this._callbacks[name].forEach(callback => {
if (typeof callback === 'function') {
callback(data || {})
}
})
}
}
export {
AdBase
}
const eventNames = [
'load',
'close',
'error',
'adClicked'
]
import {
AdBase
} from './ad-base.js'
class FullScreenVideoAd {
class FullScreenVideoAd extends AdBase {
constructor (options = {}) {
const _callbacks = this._callbacks = {}
eventNames.forEach(item => {
_callbacks[item] = []
const name = item[0].toUpperCase() + item.substr(1)
this[`on${name}`] = function (callback) {
_callbacks[item].push(callback)
}
})
this._isLoad = false
this._adError = ''
this._loadPromiseResolve = null
this._loadPromiseReject = null
this._lastLoadTime = 0
const ad = this._ad = plus.ad.createFullScreenVideoAd(options)
ad.onLoad((e) => {
this._isLoad = true
this._lastLoadTime = Date.now()
this._dispatchEvent('load', {})
if (this._loadPromiseResolve != null) {
this._loadPromiseResolve()
this._loadPromiseResolve = null
}
})
ad.onClose((e) => {
this._isLoad = false
this._dispatchEvent('close', { isEnded: e.isEnded })
})
ad.onError((e) => {
const { code, message } = e
const data = { code: code, errMsg: message }
this._adError = message
if (code === -5008) {
this._isLoad = false
}
this._dispatchEvent('error', data)
if (this._loadPromiseReject != null) {
this._loadPromiseReject(data)
this._loadPromiseReject = null
}
})
ad.onAdClicked((e) => {
this._dispatchEvent('adClicked', {})
})
}
load () {
return new Promise((resolve, reject) => {
if (this._isLoad) {
resolve()
return
}
this._loadPromiseResolve = resolve
this._loadPromiseReject = reject
this._loadAd()
})
}
show () {
return new Promise((resolve, reject) => {
if (this._isLoad) {
this._ad.show()
resolve()
} else {
reject(new Error(this._adError))
}
})
}
getProvider () {
return this._ad.getProvider()
}
destroy () {
this._ad.destroy()
}
_loadAd () {
this._isLoad = false
this._ad.load()
}
_dispatchEvent (name, data) {
this._callbacks[name].forEach(callback => {
if (typeof callback === 'function') {
callback(data || {})
}
})
super(plus.ad.createFullScreenVideoAd(options), options)
}
}
......
const eventNames = [
'load',
'close',
'error',
'adClicked'
]
import {
AdBase
} from './ad-base.js'
class InterstitialAd {
class InterstitialAd extends AdBase {
constructor (options = {}) {
const _callbacks = this._callbacks = {}
eventNames.forEach(item => {
_callbacks[item] = []
const name = item[0].toUpperCase() + item.substr(1)
this[`on${name}`] = function (callback) {
_callbacks[item].push(callback)
}
})
super(plus.ad.createInterstitialAd(options), options)
this._isLoad = false
this._isLoading = false
this._adError = ''
this._loadPromiseResolve = null
this._loadPromiseReject = null
const ad = this._ad = plus.ad.createInterstitialAd(options)
ad.onLoad((e) => {
this._isLoad = true
this._isLoading = false
this._dispatchEvent('load', {})
if (this._loadPromiseResolve != null) {
this._loadPromiseResolve()
this._loadPromiseResolve = null
}
})
ad.onClose((e) => {
this._isLoad = false
this._isLoading = false
this._dispatchEvent('close', {})
})
ad.onError((e) => {
this._isLoading = false
const { code, message } = e
const data = { code: code, errMsg: message }
this._adError = message
this._dispatchEvent('error', data)
if (this._loadPromiseReject != null) {
this._loadPromiseReject(data)
this._loadPromiseReject = null
}
})
ad.onAdClicked((e) => {
this._dispatchEvent('adClicked', {})
})
}
load () {
return new Promise((resolve, reject) => {
this._loadPromiseResolve = resolve
this._loadPromiseReject = reject
if (this._isLoading) {
return
}
if (this._isLoad) {
resolve()
return
}
this._loadAd()
})
}
show () {
return new Promise((resolve, reject) => {
if (this._isLoading) {
return
}
if (this._isLoad) {
this._ad.show()
resolve()
} else {
reject(new Error(this._adError))
}
})
}
getProvider () {
return this._ad.getProvider()
}
destroy () {
this._ad.destroy()
}
_loadAd () {
this._isLoad = false
this._isLoading = true
this._ad.load()
}
_dispatchEvent (name, data) {
this._callbacks[name].forEach(callback => {
if (typeof callback === 'function') {
callback(data || {})
}
})
this.load()
}
}
......
......@@ -30,7 +30,7 @@ function getFileInfo (filePath) {
function compressImage (tempFilePath) {
const dstPath = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(tempFilePath)}`
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
plus.nativeUI.showWaiting()
plus.zip.compressImage({
src: tempFilePath,
......@@ -39,9 +39,9 @@ function compressImage (tempFilePath) {
}, () => {
plus.nativeUI.closeWaiting()
resolve(dstPath)
}, (error) => {
}, () => {
plus.nativeUI.closeWaiting()
reject(error)
resolve(tempFilePath)
})
})
}
......
......@@ -25,16 +25,20 @@ export function chooseVideo ({
function successCallback (tempFilePath = '') {
const dst = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(tempFilePath)}`
const compressVideo = compressed ? plus.zip.compressVideo : function (_, callback) {
callback({ tempFilePath })
}
const compressVideo = compressed ? new Promise((resolve) => {
plus.zip.compressVideo({
src: tempFilePath,
dst
}, ({ tempFilePath }) => {
resolve(tempFilePath)
}, () => {
resolve(tempFilePath)
})
}) : Promise.resolve()
if (compressed) {
plus.nativeUI.showWaiting()
}
compressVideo({
src: tempFilePath,
dst
}, ({ tempFilePath }) => {
compressVideo.then(tempFilePath => {
if (compressed) {
plus.nativeUI.closeWaiting()
}
......@@ -50,12 +54,9 @@ export function chooseVideo ({
result.width = videoInfo.width
result.height = videoInfo.height
invoke(callbackId, result)
},
},
errorCallback
})
}, error => {
plus.nativeUI.closeWaiting()
errorCallback(error)
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册