html5 display audio currentTime

前端 未结 9 913
生来不讨喜
生来不讨喜 2020-11-28 05:29

I would like to display the current time of of an html 5 audio element and the duration of that element. I\'ve been looking over the internet but can\'t find a functional sc

9条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 06:24

    On TypeScript:

    formatTime(seconds: number): string {
    
        let minutes: any = Math.floor(seconds / 60);
        let secs: any = Math.floor(seconds % 60);
    
        if (minutes < 10) {
            minutes = '0' + minutes;
        }
    
        if (secs < 10) {
            secs = '0' + secs;
        }
    
        return minutes +  ':' + secs;
    }
    

    Remember to replace magic numbers with constants. It's an example.

提交回复
热议问题