diff --git a/packages/uni-app-plus/dist/index.v3.js b/packages/uni-app-plus/dist/index.v3.js index bd35a8c804f93f33b2c343c49afed6d90727e1b7..7257a1e72086703a479ee7bdb9912fdba21b77e6 100644 --- a/packages/uni-app-plus/dist/index.v3.js +++ b/packages/uni-app-plus/dist/index.v3.js @@ -8962,14 +8962,14 @@ var serviceContext = (function () { 'pause', 'stop', 'ended', - 'timeupdate', + 'timeUpdate', 'error', 'waiting', 'seeking', 'seeked' ]; - const props = [ + const props = [ { name: 'src', cache: true @@ -9022,7 +9022,7 @@ var serviceContext = (function () { this._callbacks = {}; this._options = {}; eventNames.forEach(name => { - this._callbacks[name] = []; + this._callbacks[name.toLowerCase()] = []; }); props.forEach(item => { const name = item.name; @@ -9056,11 +9056,12 @@ var serviceContext = (function () { this._operate('stop'); } seek (position) { - this._operate('play', { - currentTime: position + this._operate('seek', { + currentTime: position * 1e3 }); } destroy () { + clearInterval(this.__timing); invokeMethod('destroyAudioInstance', { audioId: this.id }); @@ -9076,6 +9077,7 @@ var serviceContext = (function () { eventNames.forEach(item => { const name = item[0].toUpperCase() + item.substr(1); + item = item.toLowerCase(); InnerAudioContext.prototype[`on${name}`] = function (callback) { this._callbacks[item].push(callback); }; @@ -9088,6 +9090,17 @@ var serviceContext = (function () { }; }); + function emit (audio, state, errMsg, errCode) { + audio._callbacks[state].forEach(callback => { + if (typeof callback === 'function') { + callback(state === 'error' ? { + errMsg, + errCode + } : {}); + } + }); + } + onMethod('onAudioStateChange', ({ state, audioId, @@ -9095,14 +9108,20 @@ var serviceContext = (function () { errCode }) => { const audio = innerAudioContexts[audioId]; - audio && audio._callbacks[state].forEach(callback => { - if (typeof callback === 'function') { - callback(state === 'error' ? { - errMsg, - errCode - } : {}); + if (audio) { + emit(audio, state, errMsg, errCode); + if (state === 'play') { + const oldCurrentTime = audio.currentTime; + audio.__timing = setInterval(() => { + const currentTime = audio.currentTime; + if (currentTime !== oldCurrentTime) { + emit(audio, 'timeupdate'); + } + }, 200); + } else if (state === 'pause' || state === 'stop' || state === 'error') { + clearInterval(audio.__timing); } - }); + } }); const innerAudioContexts = Object.create(null); diff --git a/packages/uni-app-plus/dist/service.runtime.esm.js b/packages/uni-app-plus/dist/service.runtime.esm.js index 80d9fd59cecc82bbb38cff42f825dab578bf8d28..556e2cd3535c6a62806dede91f9ace99f643259a 100644 --- a/packages/uni-app-plus/dist/service.runtime.esm.js +++ b/packages/uni-app-plus/dist/service.runtime.esm.js @@ -6642,6 +6642,53 @@ var baseModules = [ directives ]; +/* */ + +function updateWxsProps(oldVnode, vnode) { + if ( + isUndef(oldVnode.data.wxsProps) && + isUndef(vnode.data.wxsProps) + ) { + return + } + + var oldWxsWatches = oldVnode.$wxsWatches; + var wxsPropsKey = Object.keys(vnode.data.wxsProps); + if (!oldWxsWatches && !wxsPropsKey.length) { + return + } + + if (!oldWxsWatches) { + oldWxsWatches = {}; + } + + var wxsProps = vnode.data.wxsProps; + + vnode.$wxsWatches = {}; + + Object.keys(wxsProps).forEach(function (prop) { + var watchProp = wxsProps[prop]; + + vnode.$wxsWatches[prop] = oldWxsWatches[prop] || vnode.context.$watch(watchProp, function() { + this.$forceUpdate(); + }, { + deep: true + }); + }); + + Object.keys(oldWxsWatches).forEach(function (oldName) { + if (!vnode.$wxsWatches[oldName]) { + oldWxsWatches[oldName](); + delete oldWxsWatches[oldName]; + } + }); +} + +var wxs = { + create: updateWxsProps, + update: updateWxsProps +}; + function parseDataset(attrs) { var dataset = Object.create(null); Object.keys(attrs).forEach(function (name) { @@ -6765,6 +6812,7 @@ var events = { }; var platformModules = [ + wxs, attrs, events ]; diff --git a/packages/uni-cli-shared/lib/pages.js b/packages/uni-cli-shared/lib/pages.js index a2666e8c99728bf5c441facc2535592a58c2c8ca..a13820a4035d951f07c03bab7de90e630a1fbcdd 100644 --- a/packages/uni-cli-shared/lib/pages.js +++ b/packages/uni-cli-shared/lib/pages.js @@ -334,7 +334,7 @@ let uniAutoImportComponents = [] let uniAutoImportScanComponents = [] -function initAutoImportScanComponents () { +function initAutoImportScanComponents () { const componentsPath = path.resolve(process.env.UNI_INPUT_DIR, 'components') const components = {} try { @@ -347,12 +347,22 @@ function initAutoImportScanComponents () { }) } catch (e) {} - uniAutoImportScanComponents = parseUsingAutoImportComponents(components) - + uniAutoImportScanComponents = parseUsingAutoImportComponents(components) + refreshAutoComponentMap() } -function initAutoImportComponents (usingAutoImportComponents = {}) { +const _toString = Object.prototype.toString + +function isPlainObject (obj) { + return _toString.call(obj) === '[object Object]' +} + +function initAutoImportComponents (easycom = {}) { + let usingAutoImportComponents = easycom.custom || easycom || {} + if (!isPlainObject(usingAutoImportComponents)) { + usingAutoImportComponents = {} + } // 目前仅 mp-weixin 内置支持 page-meta 等组件 if (process.env.UNI_PLATFORM !== 'mp-weixin') { if (!usingAutoImportComponents['^page-meta$']) { @@ -415,10 +425,13 @@ function parseUsingAutoImportComponents (usingAutoImportComponents) { const autoImportComponents = [] if (usingAutoImportComponents) { Object.keys(usingAutoImportComponents).forEach(pattern => { - autoImportComponents.push({ - pattern: new RegExp(pattern), - replacement: usingAutoImportComponents[pattern] - }) + const replacement = usingAutoImportComponents[pattern] + if (replacement && typeof replacement === 'string') { + autoImportComponents.push({ + pattern: new RegExp(pattern), + replacement: replacement + }) + } }) } return autoImportComponents @@ -432,7 +445,7 @@ module.exports = { parsePagesJson, pagesJsonJsFileName, getAutoComponents, - initAutoImportComponents, + initAutoImportComponents, initAutoImportScanComponents, addPageUsingComponents, getUsingComponentsCode, diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js index 193b7a6af8659e006997e20ea20cacaf4a3029b9..c24d39d87f3c7b8d91ec9c6bfcfad64edc8245a9 100644 --- a/packages/vue-cli-plugin-uni/lib/env.js +++ b/packages/vue-cli-plugin-uni/lib/env.js @@ -312,12 +312,15 @@ if ( } const { - initAutoImportComponents, + initAutoImportComponents, initAutoImportScanComponents -} = require('@dcloudio/uni-cli-shared/lib/pages') - -initAutoImportScanComponents() -initAutoImportComponents(pagesJsonObj.easycom) +} = require('@dcloudio/uni-cli-shared/lib/pages') + +process.UNI_AUTO_SCAN_COMPONENTS = !(pagesJsonObj.easycom && pagesJsonObj.easycom.autoscan === false) +initAutoImportComponents(pagesJsonObj.easycom) +if (process.UNI_AUTO_SCAN_COMPONENTS) { + initAutoImportScanComponents() +} runByHBuilderX && console.log(`正在编译中...`) diff --git a/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.common.js b/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.common.js index b552c428ddb89d0e2f769f0b0deea8f07f984e46..c26ba4ebe60b0a0c2a9b230aa486ab796953a26a 100644 --- a/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.common.js +++ b/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.common.js @@ -1,6 +1,6 @@ /*! * vue-router v3.0.1 - * (c) 2019 Evan You + * (c) 2020 Evan You * @license MIT */ 'use strict'; @@ -1325,7 +1325,6 @@ function normalizeLocation ( /* */ - function createMatcher ( routes, router @@ -1495,7 +1494,7 @@ function createMatcher ( if (record.meta.id) { record.components.default.name = record.meta.name + '-' + location.params.__id__; } else { - record = Object.assign({}, record); + record = extend({}, record); record.components = { 'default': { name: record.meta.name + '-' + location.params.__id__, diff --git a/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.esm.js b/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.esm.js index 19ec64b2a1aa0810602bc82291f1deca9ff7230d..dee50aaabb861f7ee8dd65ea226dd6bdd73f8ec6 100644 --- a/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.esm.js +++ b/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.esm.js @@ -1,6 +1,6 @@ /*! * vue-router v3.0.1 - * (c) 2019 Evan You + * (c) 2020 Evan You * @license MIT */ /* */ @@ -1323,7 +1323,6 @@ function normalizeLocation ( /* */ - function createMatcher ( routes, router @@ -1493,7 +1492,7 @@ function createMatcher ( if (record.meta.id) { record.components.default.name = record.meta.name + '-' + location.params.__id__; } else { - record = Object.assign({}, record); + record = extend({}, record); record.components = { 'default': { name: record.meta.name + '-' + location.params.__id__, diff --git a/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.js b/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.js index ef0d4d83fe9c954bab206a20cfda4322c75d3c30..b14fd7029689289c66d4a188a43103a0eae5aa0c 100644 --- a/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.js +++ b/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.js @@ -1,6 +1,6 @@ /*! * vue-router v3.0.1 - * (c) 2019 Evan You + * (c) 2020 Evan You * @license MIT */ (function (global, factory) { @@ -1329,7 +1329,6 @@ function normalizeLocation ( /* */ - function createMatcher ( routes, router @@ -1499,7 +1498,7 @@ function createMatcher ( if (record.meta.id) { record.components.default.name = record.meta.name + '-' + location.params.__id__; } else { - record = Object.assign({}, record); + record = extend({}, record); record.components = { 'default': { name: record.meta.name + '-' + location.params.__id__, diff --git a/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.min.js b/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.min.js index 63223428f645132b8efe54bcb3d8d3f5a0e9840d..4c22c7ef641f83b4e83cbd438c7368cd36d21ae6 100644 --- a/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.min.js +++ b/packages/vue-cli-plugin-uni/packages/h5-vue-router/dist/vue-router.min.js @@ -1,6 +1,6 @@ /*! * vue-router v3.0.1 - * (c) 2019 Evan You + * (c) 2020 Evan You * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function l(t){return-1=e.length?n():e[t]?r(e[t],function(){o(t+1)}):o(t+1)};o(0)}function ut(r){return function(t,e,u){var c=!1,p=0,f=null;ct(r,function(r,t,n,o){if("function"==typeof r&&void 0===r.cid){c=!0,p++;var e,i=ht(function(t){var e;((e=t).__esModule||ft&&"Module"===e[Symbol.toStringTag])&&(t=t.default),r.resolved="function"==typeof t?t:d.extend(t),n.components[o]=t,--p<=0&&u()}),a=ht(function(t){var e="Failed to resolve async component "+o+": "+t;f||(f=l(t)?t:new Error(e),u(f))});try{e=r(i,a)}catch(t){a(t)}if(e)if("function"==typeof e.then)e.then(i,a);else{var s=e.component;s&&"function"==typeof s.then&&s.then(i,a)}}}),c||u()}}function ct(t,r){return pt(t.map(function(e){return Object.keys(e.components).map(function(t){return r(e.components[t],e.instances[t],e,t)})}))}function pt(t){return Array.prototype.concat.apply([],t)}var ft="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function ht(r){var n=!1;return function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(!n)return n=!0,r.apply(this,t)}}var lt=function(t,e){this.router=t,this.base=function(t){if(!t)if(y){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";"/"!==t.charAt(0)&&(t="/"+t);return t.replace(/\/$/,"")}(e),this.current=O,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]};function dt(t,i,a,e){var r=ct(t,function(t,e,r,n){var o=function(t,e){"function"!=typeof t&&(t=d.extend(t));return t.options[e]}(t,i);if(o)return Array.isArray(o)?o.map(function(t){return a(t,e,r,n)}):a(o,e,r,n)});return pt(e?r.reverse():r)}function yt(t,e){if(e)return function(){return t.apply(e,arguments)}}lt.prototype.listen=function(t){this.cb=t},lt.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},lt.prototype.onError=function(t){this.errorCbs.push(t)},lt.prototype.transitionTo=function(t,e,r){var n=this,o=this.router.match(t,this.current);this.confirmTransition(o,function(){n.updateRoute(o),e&&e(o),n.ensureURL(),n.ready||(n.ready=!0,n.readyCbs.forEach(function(t){t(o)}))},function(e){r&&r(e),e&&!n.ready&&(n.ready=!0,n.readyErrorCbs.forEach(function(t){t(e)}))})},lt.prototype.confirmTransition=function(r,e,t){var n=this,o=this.current,i=function(e){l(e)&&(n.errorCbs.length?n.errorCbs.forEach(function(t){t(e)}):console.error(e)),t&&t(e)},a=function(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r=this.stack.length)){var n=this.stack[r];this.confirmTransition(n,function(){e.index=r,e.updateRoute(n)})}},t.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},t.prototype.ensureURL=function(){},t}(lt),Et=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=D(t.routes||[],this),this.id=t.id||1,this.minId=t.id||1;var e=t.mode||"hash";switch(this.fallback="history"===e&&!tt&&!1!==t.fallback,this.fallback&&(e="hash"),y||(e="abstract"),this.mode=e){case"history":this.history=new vt(this,t.base);break;case"hash":this.history=new gt(this,t.base,this.fallback);break;case"abstract":this.history=new kt(this,t.base)}},jt={currentRoute:{configurable:!0}};function Ot(e,r){return e.push(r),function(){var t=e.indexOf(r);-1=e.length?n():e[t]?r(e[t],function(){o(t+1)}):o(t+1)};o(0)}function ut(r){return function(t,e,u){var c=!1,p=0,f=null;ct(r,function(r,t,n,o){if("function"==typeof r&&void 0===r.cid){c=!0,p++;var e,i=ht(function(t){var e;((e=t).__esModule||ft&&"Module"===e[Symbol.toStringTag])&&(t=t.default),r.resolved="function"==typeof t?t:d.extend(t),n.components[o]=t,--p<=0&&u()}),a=ht(function(t){var e="Failed to resolve async component "+o+": "+t;f||(f=l(t)?t:new Error(e),u(f))});try{e=r(i,a)}catch(t){a(t)}if(e)if("function"==typeof e.then)e.then(i,a);else{var s=e.component;s&&"function"==typeof s.then&&s.then(i,a)}}}),c||u()}}function ct(t,r){return pt(t.map(function(e){return Object.keys(e.components).map(function(t){return r(e.components[t],e.instances[t],e,t)})}))}function pt(t){return Array.prototype.concat.apply([],t)}var ft="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function ht(r){var n=!1;return function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(!n)return n=!0,r.apply(this,t)}}var lt=function(t,e){this.router=t,this.base=function(t){if(!t)if(y){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";"/"!==t.charAt(0)&&(t="/"+t);return t.replace(/\/$/,"")}(e),this.current=O,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]};function dt(t,i,a,e){var r=ct(t,function(t,e,r,n){var o=function(t,e){"function"!=typeof t&&(t=d.extend(t));return t.options[e]}(t,i);if(o)return Array.isArray(o)?o.map(function(t){return a(t,e,r,n)}):a(o,e,r,n)});return pt(e?r.reverse():r)}function yt(t,e){if(e)return function(){return t.apply(e,arguments)}}lt.prototype.listen=function(t){this.cb=t},lt.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},lt.prototype.onError=function(t){this.errorCbs.push(t)},lt.prototype.transitionTo=function(t,e,r){var n=this,o=this.router.match(t,this.current);this.confirmTransition(o,function(){n.updateRoute(o),e&&e(o),n.ensureURL(),n.ready||(n.ready=!0,n.readyCbs.forEach(function(t){t(o)}))},function(e){r&&r(e),e&&!n.ready&&(n.ready=!0,n.readyErrorCbs.forEach(function(t){t(e)}))})},lt.prototype.confirmTransition=function(r,e,t){var n=this,o=this.current,i=function(e){l(e)&&(n.errorCbs.length?n.errorCbs.forEach(function(t){t(e)}):console.error(e)),t&&t(e)},a=function(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r=this.stack.length)){var n=this.stack[r];this.confirmTransition(n,function(){e.index=r,e.updateRoute(n)})}},t.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},t.prototype.ensureURL=function(){},t}(lt),Et=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=D(t.routes||[],this),this.id=t.id||1,this.minId=t.id||1;var e=t.mode||"hash";switch(this.fallback="history"===e&&!tt&&!1!==t.fallback,this.fallback&&(e="hash"),y||(e="abstract"),this.mode=e){case"history":this.history=new vt(this,t.base);break;case"hash":this.history=new gt(this,t.base,this.fallback);break;case"abstract":this.history=new kt(this,t.base)}},jt={currentRoute:{configurable:!0}};function Ot(e,r){return e.push(r),function(){var t=e.indexOf(r);-1 { if (fileName && typeof fileName === 'string') { if (fileName.indexOf('.vue') !== -1 || fileName.indexOf('.nvue') !== -1) { - initAutoImportScanComponents() + if (process.UNI_AUTO_SCAN_COMPONENTS) { + initAutoImportScanComponents() + } } } }) diff --git a/packages/webpack-uni-pages-loader/lib/index-new.js b/packages/webpack-uni-pages-loader/lib/index-new.js index dee90251e02f246d85d8b2ea09c07c5e196f161b..57d258403b8cd3cd02846fda361066c7b36b0040 100644 --- a/packages/webpack-uni-pages-loader/lib/index-new.js +++ b/packages/webpack-uni-pages-loader/lib/index-new.js @@ -56,6 +56,7 @@ module.exports = function (content) { }) // 组件自动导入配置 + process.UNI_AUTO_SCAN_COMPONENTS = !(pagesJson.easycom && pagesJson.easycom.autoscan === false) initAutoImportComponents(pagesJson.easycom) // TODO 与 usingComponents 放在一块读取设置 @@ -128,4 +129,4 @@ module.exports = function (content) { } return '' -} +} diff --git a/src/core/helpers/hidpi.js b/src/core/helpers/hidpi.js index 0245c690d953fbe4e11e5e7790e6e457a9896675..88eae7d67612c9f8e7a91b6a013172d3932bf8da 100644 --- a/src/core/helpers/hidpi.js +++ b/src/core/helpers/hidpi.js @@ -36,9 +36,9 @@ const ratioArgs = { 'createLinearGradient': 'all', 'setTransform': [4, 5] } -if (pixelRatio !== 1) { - const proto = CanvasRenderingContext2D.prototype +const proto = CanvasRenderingContext2D.prototype +if (pixelRatio !== 1) { forEach(ratioArgs, function (value, key) { proto[key] = (function (_super) { return function () { @@ -129,23 +129,6 @@ if (pixelRatio !== 1) { } })(proto.strokeText) - proto.drawImageByCanvas = (function (_super) { - return function (canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh, isScale) { - if (!this.__hidpi__) { - return _super.apply(this, arguments) - } - srcx *= pixelRatio - srcy *= pixelRatio - srcw *= pixelRatio - srch *= pixelRatio - desx *= pixelRatio - desy *= pixelRatio - desw = isScale ? desw * pixelRatio : desw - desh = isScale ? desh * pixelRatio : desh - _super.call(this, canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh) - } - })(proto.drawImage) - proto.drawImage = (function (_super) { return function () { if (!this.__hidpi__) { @@ -158,6 +141,23 @@ if (pixelRatio !== 1) { })(proto.drawImage) } +proto.drawImageByCanvas = (function (_super) { + return function (canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh, isScale) { + if (!this.__hidpi__) { + return _super.apply(this, arguments) + } + srcx *= pixelRatio + srcy *= pixelRatio + srcw *= pixelRatio + srch *= pixelRatio + desx *= pixelRatio + desy *= pixelRatio + desw = isScale ? desw * pixelRatio : desw + desh = isScale ? desh * pixelRatio : desh + _super.call(this, canvas, srcx, srcy, srcw, srch, desx, desy, desw, desh) + } +})(proto.drawImage) + export function wrapper (canvas) { canvas.width = canvas.offsetWidth * pixelRatio canvas.height = canvas.offsetHeight * pixelRatio diff --git a/src/core/service/api/context/audio.js b/src/core/service/api/context/audio.js index 78aedc7c919cba6aeb4642e9f857a2c248bae882..004d8dd8ba5fe810d82b43c3e7b91f24c9a90559 100644 --- a/src/core/service/api/context/audio.js +++ b/src/core/service/api/context/audio.js @@ -9,14 +9,14 @@ const eventNames = [ 'pause', 'stop', 'ended', - 'timeupdate', + 'timeUpdate', 'error', 'waiting', 'seeking', 'seeked' ] -const props = [ +const props = [ { name: 'src', cache: true @@ -69,7 +69,7 @@ class InnerAudioContext { this._callbacks = {} this._options = {} eventNames.forEach(name => { - this._callbacks[name] = [] + this._callbacks[name.toLowerCase()] = [] }) props.forEach(item => { const name = item.name @@ -103,11 +103,12 @@ class InnerAudioContext { this._operate('stop') } seek (position) { - this._operate('play', { - currentTime: position + this._operate('seek', { + currentTime: position * 1e3 }) } destroy () { + clearInterval(this.__timing) invokeMethod('destroyAudioInstance', { audioId: this.id }) @@ -123,6 +124,7 @@ class InnerAudioContext { eventNames.forEach(item => { const name = item[0].toUpperCase() + item.substr(1) + item = item.toLowerCase() InnerAudioContext.prototype[`on${name}`] = function (callback) { this._callbacks[item].push(callback) } @@ -135,6 +137,17 @@ eventNames.forEach(item => { } }) +function emit (audio, state, errMsg, errCode) { + audio._callbacks[state].forEach(callback => { + if (typeof callback === 'function') { + callback(state === 'error' ? { + errMsg, + errCode + } : {}) + } + }) +} + onMethod('onAudioStateChange', ({ state, audioId, @@ -142,14 +155,20 @@ onMethod('onAudioStateChange', ({ errCode }) => { const audio = innerAudioContexts[audioId] - audio && audio._callbacks[state].forEach(callback => { - if (typeof callback === 'function') { - callback(state === 'error' ? { - errMsg, - errCode - } : {}) + if (audio) { + emit(audio, state, errMsg, errCode) + if (state === 'play') { + const oldCurrentTime = audio.currentTime + audio.__timing = setInterval(() => { + const currentTime = audio.currentTime + if (currentTime !== oldCurrentTime) { + emit(audio, 'timeupdate') + } + }, 200) + } else if (state === 'pause' || state === 'stop' || state === 'error') { + clearInterval(audio.__timing) } - }) + } }) const innerAudioContexts = Object.create(null) @@ -161,4 +180,4 @@ export function createInnerAudioContext () { const innerAudioContext = new InnerAudioContext(audioId) innerAudioContexts[audioId] = innerAudioContext return innerAudioContext -} +}