Skip to content

Instantly share code, notes, and snippets.

@getchenge
Created April 11, 2019 10:59
Show Gist options
  • Save getchenge/6472a49c96a50751b3c5478079744719 to your computer and use it in GitHub Desktop.
Save getchenge/6472a49c96a50751b3c5478079744719 to your computer and use it in GitHub Desktop.
get audio duration in wechat MINA app
getDuration: function(audio, id) {
const {
durations = {},
retry = {}
} = this.data;
let {
duration
} = audio;
console.info('audio.duration', audio.duration);
if (duration == 0) {
retry[id] = retry[id] || 0;
return setTimeout(() => {
if (retry[id] > 10) { // retry at most 9 times
return
}
retry[id] += 1;
this.setData({
retry
});
this.getDuration(audio, id)
}, 300);
}
retry[id] = 0;
durations[id] = this.timeFormat(duration);
this.setData({
durations,
retry
});
}
@getchenge
Copy link
Author

@params id, the unique id of audio stored in DB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment