veplayer-mp-douyin
Advanced tools
Comparing version 1.2.7-alpha.0 to 1.2.7-alpha.1
@@ -43,4 +43,2 @@ "use strict"; | ||
playerStyle: '', | ||
// 可否可使用video以外的其他tagType | ||
canUseOtherType: true, | ||
// video-player是否已经触发过getsource可以播放 | ||
@@ -50,20 +48,5 @@ videoPlayerCanPlay: false, | ||
lifetimes: { | ||
attached() { | ||
const { tagType } = this.properties; | ||
let canUse = true; | ||
if (tagType !== "video" /* TAG_TYPE.VIDEO */) { | ||
// 如果不能使用指定的tagType,则降级成video | ||
canUse = tt.canIUse(tagType); | ||
if (!canUse) { | ||
console.warn(`tagType: ${tagType} cannot support in current app version`); | ||
} | ||
} | ||
this.setData({ | ||
canUseOtherType: canUse, | ||
}); | ||
utils_1.VE_DEBUGGER.log('canUseOtherType', canUse, this.properties.tagType); | ||
}, | ||
ready() { | ||
// TODO video-player有bug,css百分比宽高不能生效,只能通过style固定值设置,等后续bug修复后去掉该函数调用 | ||
this.setVideoPlayerStyle(); | ||
// this.setVideoPlayerStyle() | ||
this.onAidEidChange(); | ||
@@ -77,3 +60,3 @@ this.onTagTypeChange(); | ||
}, | ||
'canUseOtherType, tagType': function () { | ||
tagType: function () { | ||
this.onTagTypeChange(); | ||
@@ -85,17 +68,34 @@ } | ||
const { albumId, episodeId } = this.data; | ||
this.setData({ | ||
videoPlayerCanPlay: false, | ||
isLoadingData: false, | ||
error: null, | ||
isHidden: false, | ||
}); | ||
this.updateCollector({ | ||
albumId, | ||
episodeId | ||
}); | ||
if (albumId && episodeId) { | ||
const canUse = tt.canIUse("video-player" /* TAG_TYPE.VIDEO_PLAYER */); | ||
if (canUse) { | ||
this.setData({ | ||
tagType: "video-player" /* TAG_TYPE.VIDEO_PLAYER */, | ||
videoPlayerCanPlay: false, | ||
isLoadingData: false, | ||
error: null, | ||
isHidden: false, | ||
}); | ||
this.updateCollector({ | ||
albumId, | ||
episodeId | ||
}); | ||
} | ||
else { | ||
this.setData({ | ||
tagType: "video" /* TAG_TYPE.VIDEO */, | ||
}); | ||
utils_1.VE_DEBUGGER.warn(`component video-player cannot support in current app version`); | ||
} | ||
} | ||
else { | ||
this.setData({ | ||
tagType: "video" /* TAG_TYPE.VIDEO */, | ||
}); | ||
} | ||
}, | ||
onTagTypeChange() { | ||
const { canUseOtherType, tagType } = this.data; | ||
const { tagType } = this.data; | ||
this.updateCollector({ | ||
isVideoPlayer: canUseOtherType && tagType === "video-player" /* TAG_TYPE.VIDEO_PLAYER */ | ||
isVideoPlayer: tagType === "video-player" /* TAG_TYPE.VIDEO_PLAYER */ | ||
}); | ||
@@ -102,0 +102,0 @@ }, |
@@ -35,2 +35,7 @@ "use strict"; | ||
}, | ||
// 当前实例是否是激活状态 | ||
activeState: { | ||
type: String, | ||
value: 'default', // standby - 备用状态 active - 激活撞他 | ||
}, | ||
}, | ||
@@ -65,2 +70,7 @@ data: { | ||
}, | ||
activeState: function activeState() { | ||
const { activeState } = this.data; | ||
index_1.VE_DEBUGGER.log('activeState change', activeState); | ||
this.triggerCollector(index_2.ExtendsEvents.ACTIVE, { activeState }); | ||
}, | ||
}, | ||
@@ -67,0 +77,0 @@ lifetimes: { |
@@ -27,3 +27,3 @@ "use strict"; | ||
exports.PKG = 'douyin'; | ||
exports.VERSION = '1.2.7-alpha.0'; | ||
exports.VERSION = '1.2.7-alpha.1'; | ||
/** | ||
@@ -30,0 +30,0 @@ * 控制栏状态枚举 |
@@ -27,8 +27,2 @@ "use strict"; | ||
// }, | ||
// tag的类型,用来继承其他标签 | ||
// 支持的值 'video', 'video-player' | ||
tagType: { | ||
type: String, | ||
value: 'video-player', | ||
}, | ||
mode: { | ||
@@ -81,7 +75,2 @@ type: String, | ||
}, | ||
// 当前实例是否是激活状态 | ||
isActive: { | ||
type: Boolean, | ||
value: true, | ||
}, | ||
}, | ||
@@ -118,3 +107,4 @@ data: { | ||
customControls: false, | ||
isHidden: true, // 是否隐藏video组件 | ||
isHidden: true, | ||
tagType: "video" /* TAG_TYPE.VIDEO */, // tag的类型,用来继承其他标签, 支持的值 'video', 'video-player' | ||
}, | ||
@@ -128,2 +118,6 @@ observers: { | ||
// }, | ||
componentId: function () { | ||
// componentId变化时则重新设置videoContext | ||
this.setVideoContext(); | ||
}, | ||
seeking: function (flag) { | ||
@@ -138,7 +132,2 @@ this._emitEvt(flag ? index_1.MediaEvents.SEEKING : index_1.MediaEvents.SEEKCOMPLETE, {}); | ||
}, | ||
'isActive': function () { | ||
const { isActive } = this.data; | ||
index_2.VE_DEBUGGER.log('isActive change', isActive); | ||
this.triggerCollector(index_1.ExtendsEvents.ACTIVE, { isActive }); | ||
}, | ||
'currentSrc': function () { | ||
@@ -157,5 +146,5 @@ const { currentSrc, src, videoId } = this.data; | ||
'src,definitionList,playAuthToken,playDomain': function () { | ||
const { src, definitionList, playAuthToken, playDomain, isLoadingData, videoId } = this.data; | ||
const { src, definitionList, playAuthToken, playDomain, isLoadingData, videoId, currentSrc } = this.data; | ||
index_2.VE_DEBUGGER.log('sourceChange', videoId, `src:${!!src} playAuthToken:${!!playAuthToken} isLoadingData:${isLoadingData}`); | ||
this.triggerCollector('break'); | ||
currentSrc !== src && this.triggerCollector('break'); | ||
this.updateCollector(this.data); | ||
@@ -221,17 +210,5 @@ // playAuthToken | ||
var _a; | ||
const { componentId, tagType } = this.properties; | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const self = this; | ||
const { videoId, videoProps, isFullScreen, canUseOtherType } = this.data; | ||
// const { controls } = this.properties | ||
let _videoId = videoId || componentId; | ||
if (!_videoId) { | ||
_videoId = (0, index_2.generateUppercaseUid)(); | ||
} | ||
this.setData({ | ||
videoId: _videoId, | ||
// customControls: controls !== 'native', | ||
}); | ||
const isVideoPlayer = tagType === "video-player" /* TAG_TYPE.VIDEO_PLAYER */ && canUseOtherType; | ||
const videoCtx = tt.createVideoContext(_videoId, isVideoPlayer ? this.videoPlayer : this); | ||
const { videoProps, isFullScreen } = this.data; | ||
const propsClassNames = ((_a = videoProps.className) === null || _a === void 0 ? void 0 : _a.split(' ')) || []; | ||
@@ -242,48 +219,4 @@ const classNames = [ | ||
].filter((item) => !!item); | ||
// const showCtrlOverlay = (loadedMeta && toggleCtrlOverLayer) || ended | ||
const videoProxyCtx = new Proxy(videoCtx, { | ||
get(target, prop, receiver) { | ||
// Use the proxy to hijack the seek method and set the seeking state change | ||
if (prop === 'seek') { | ||
self.setData({ | ||
seeking: true, | ||
}); | ||
} | ||
if (prop === 'play') { | ||
const playFn = Reflect.get(target, 'play', receiver); | ||
// play 返回promise,可以根据返回结果判断是否play成功 | ||
return () => new Promise((resolve, reject) => { | ||
self.media.once(index_1.MediaEvents.ERROR, (err) => { | ||
reject(err); | ||
}); | ||
// 注意这里IDE模拟器里,即使地址之类错误,也会触发一次TIMEUPDATE,而真机则不会,可忽略IDE的行为 | ||
self.media.once(index_1.MediaEvents.TIMEUPDATE, () => { | ||
resolve(null); | ||
}); | ||
const { videoPlayerCanPlay } = self.data; | ||
if (isVideoPlayer) { | ||
if (videoPlayerCanPlay) { | ||
playFn(); | ||
} | ||
else { | ||
self.media.once(index_1.MediaEvents.GETSOURCE, () => { | ||
playFn(); | ||
}); | ||
} | ||
} | ||
else { | ||
playFn(); | ||
} | ||
}); | ||
} | ||
return Reflect.get(target, prop, receiver); | ||
}, | ||
}); | ||
if (Object.isExtensible(videoProxyCtx)) { | ||
// eslint-disable-next-line @typescript-eslint/dot-notation | ||
!videoProxyCtx['on'] && Object.assign(videoProxyCtx, new eventemitter3_1.EventEmitter(), eventemitter3_1.EventEmitter.prototype); | ||
this.media = videoProxyCtx; | ||
} | ||
index_3.default.setMedia(_videoId, this.media); | ||
this.setData({ classNames: classNames.join(' ') }); | ||
this.setVideoContext(); | ||
}, | ||
@@ -338,2 +271,59 @@ /** | ||
methods: { | ||
setVideoContext() { | ||
const { videoId, componentId, tagType } = this.data; | ||
let _videoId = videoId || componentId; | ||
if (!_videoId) { | ||
_videoId = (0, index_2.generateUppercaseUid)(); | ||
} | ||
this.setData({ | ||
videoId: _videoId, | ||
}); | ||
const isVideoPlayer = tagType === "video-player" /* TAG_TYPE.VIDEO_PLAYER */; | ||
const videoCtx = tt.createVideoContext(_videoId, isVideoPlayer ? this.videoPlayer : this); | ||
const self = this; | ||
const videoProxyCtx = new Proxy(videoCtx, { | ||
get(target, prop, receiver) { | ||
// Use the proxy to hijack the seek method and set the seeking state change | ||
if (prop === 'seek') { | ||
self.setData({ | ||
seeking: true, | ||
}); | ||
} | ||
if (prop === 'play') { | ||
const playFn = Reflect.get(target, 'play', receiver); | ||
// play 返回promise,可以根据返回结果判断是否play成功 | ||
return () => new Promise((resolve, reject) => { | ||
self.media.once(index_1.MediaEvents.ERROR, (err) => { | ||
reject(err); | ||
}); | ||
// 注意这里IDE模拟器里,即使地址之类错误,也会触发一次TIMEUPDATE,而真机则不会,可忽略IDE的行为 | ||
self.media.once(index_1.MediaEvents.TIMEUPDATE, () => { | ||
resolve(null); | ||
}); | ||
const { videoPlayerCanPlay } = self.data; | ||
if (isVideoPlayer) { | ||
if (videoPlayerCanPlay) { | ||
playFn(); | ||
} | ||
else { | ||
self.media.once(index_1.MediaEvents.GETSOURCE, () => { | ||
playFn(); | ||
}); | ||
} | ||
} | ||
else { | ||
playFn(); | ||
} | ||
}); | ||
} | ||
return Reflect.get(target, prop, receiver); | ||
}, | ||
}); | ||
if (Object.isExtensible(videoProxyCtx)) { | ||
// eslint-disable-next-line @typescript-eslint/dot-notation | ||
!videoProxyCtx['on'] && Object.assign(videoProxyCtx, new eventemitter3_1.EventEmitter(), eventemitter3_1.EventEmitter.prototype); | ||
this.media = videoProxyCtx; | ||
} | ||
index_3.default.setMedia(_videoId, this.media); | ||
}, | ||
canIUse(type) { | ||
@@ -442,10 +432,10 @@ return tt.canIUse(type); | ||
onTimeupdate(e) { | ||
const { seeking } = this.data; | ||
const { seeking, paused } = this.data; | ||
const { currentTime, duration } = e.detail; | ||
const data = { | ||
currentTime: currentTime || 0, | ||
paused: false, | ||
duration: duration || 0, | ||
playPercent: duration > 0 ? Math.floor((currentTime / duration) * 100) : 0, | ||
}; | ||
let ext = {}; | ||
if (this.isReplay && paused) { | ||
ext = { paused: false }; | ||
this.isReplay = false; | ||
} | ||
const data = Object.assign({ currentTime: currentTime || 0, duration: duration || 0, playPercent: duration > 0 ? Math.floor((currentTime / duration) * 100) : 0 }, ext); | ||
if (seeking) { | ||
@@ -471,2 +461,3 @@ // /* 开发工具中不会触发onSeekComplete */ | ||
}; | ||
this.isReplay = true; | ||
if (seeking) { | ||
@@ -473,0 +464,0 @@ _data.seeking = false; |
@@ -142,3 +142,3 @@ "use strict"; | ||
this.dragStartTime = -1; | ||
this.media.seek(seekTime); | ||
this.media && this.media.seek(seekTime); | ||
}, | ||
@@ -145,0 +145,0 @@ onProgressChanging(e) { |
{ | ||
"name": "veplayer-mp-douyin", | ||
"version": "1.2.7-alpha.0", | ||
"version": "1.2.7-alpha.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "miniprogramType": "tt-npm", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
162181
3048