Created
April 11, 2019 10:59
-
-
Save getchenge/6472a49c96a50751b3c5478079744719 to your computer and use it in GitHub Desktop.
get audio duration in wechat MINA app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@params id, the unique id of audio stored in DB