调整分包,完成隐私协议(样式待优化)
This commit is contained in:
100
childPackage/miniprogram_npm/towxml/audio-player/audio-player.js
Normal file
100
childPackage/miniprogram_npm/towxml/audio-player/audio-player.js
Normal file
@@ -0,0 +1,100 @@
|
||||
const Audio = require('./Audio');
|
||||
Component({
|
||||
options: {
|
||||
styleIsolation: 'shared'
|
||||
},
|
||||
properties: {
|
||||
data: {
|
||||
type: Object,
|
||||
value: {}
|
||||
}
|
||||
},
|
||||
lifetimes:{
|
||||
// 页面生命周期
|
||||
attached:function(){
|
||||
const _ts = this,
|
||||
audio = _ts.audio = new Audio(this.data.data);
|
||||
|
||||
audio.eventPlay = function(){
|
||||
_ts.setData({tips:{state:'h2w__audio--play',text:'Playing'}});
|
||||
};
|
||||
audio.eventCanplay = function(){
|
||||
_ts.setData({tips:{state:'h2w__audio--readyed',text:'Readyed'}});
|
||||
};
|
||||
audio.eventTimeUpdate = function(duration,currentTime){
|
||||
_ts.setData({time:{currentTime:currentTime,duration:duration,schedule:Math.round(_ts.audio.currentTime) / Math.round(_ts.audio.duration) * 100 + '%'}});
|
||||
};
|
||||
audio.eventPause = function(){
|
||||
_ts.setData({tips:{state:'h2w__audio--pause',text:'Pause'}});
|
||||
};
|
||||
audio.eventStop = function(){
|
||||
_ts.setData({tips:{state:'h2w__audio--end',text:'End'}});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // 更新播放状态
|
||||
// _ts.audio.onTimeUpdate = function(duration,currentTime){
|
||||
// _ts.setData({
|
||||
// playerData:{
|
||||
// state:'h2w__audio--play',
|
||||
// tips:'Playing',
|
||||
// currentTime:currentTime,
|
||||
// duration:duration,
|
||||
// schedule:_ts.audio.currentTime / _ts.audio.duration * 100 + '%'
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
|
||||
// _ts.audio.onPause = function(){
|
||||
// _ts.setData({playerData:{state:'h2w__audio--pause',tips:'Pause'}});
|
||||
// };
|
||||
|
||||
// _ts.audio.onCanplay = function(){
|
||||
// _ts.setData({playerData:{state:'h2w__audio--readyed',tips:'Readyed'}});
|
||||
// };
|
||||
|
||||
// _ts.audio.onError = function(){
|
||||
// _ts.setData({playerData:{state:'h2w__audio--error',tips:'Error'}});
|
||||
// };
|
||||
|
||||
// _ts.audio.onEnded = ()=>{
|
||||
// _ts.setData({playerData:{state:'h2w__audio--end',tips:'End'}});
|
||||
// };
|
||||
|
||||
},
|
||||
moved:function(){
|
||||
_ts.audio.stop();
|
||||
_ts.audio.destroy();
|
||||
},
|
||||
detached:()=>{
|
||||
_ts.audio.stop();
|
||||
_ts.audio.destroy();
|
||||
},
|
||||
},
|
||||
data: {
|
||||
tips:{
|
||||
state:'',
|
||||
text:'--'
|
||||
},
|
||||
time: {
|
||||
currentTime:'00:00:00',
|
||||
duration:'00:00:00',
|
||||
schedule:'0%'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
playAndPause: function () {
|
||||
const _ts = this,
|
||||
audio = _ts.audio;
|
||||
audio.isTouch = true;
|
||||
if(audio.status === 'update' || audio.status === 'play'){
|
||||
audio.pause();
|
||||
}else{
|
||||
audio.play();
|
||||
};
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user