提交 0039c1e8 编写于 作者: Q qiang

fix: 解决H5端 innerAudioContext.src 不支持相对路径的问题

上级 5714e649
import getRealPath from 'uni-platform/helpers/get-real-path'
/**
* 可以批量设置的监听事件
*/
......@@ -25,6 +27,10 @@ class InnerAudioContext {
* 事件监听
*/
_events
/**
* 音频地址
*/
_src
/**
* 音频上下文初始化
*/
......@@ -32,15 +38,19 @@ class InnerAudioContext {
var audio = this._audio = new Audio()
this._stoping = false
// 和audio对象同名同效果的属性
var watchers = ['src', 'autoplay', 'loop', 'duration', 'currentTime', 'paused', 'volume']
watchers.forEach((watcher) => {
Object.defineProperty(this, watcher, {
set (val) {
audio[watcher] = val
return audio[watcher]
var propertys = ['src', 'autoplay', 'loop', 'duration', 'currentTime', 'paused', 'volume']
propertys.forEach((property) => {
Object.defineProperty(this, property, {
set: property === 'src' ? (src) => {
audio.src = getRealPath(src)
return this._src = src
} : (val) => {
return audio[property] = val
},
get () {
return audio[watcher]
get: property === 'src' ? () => {
return this._src
} : () => {
return audio[property]
}
})
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册