我試圖顯示實時播放的曲目的剩餘時間,但無法弄清楚,因爲我的JavaScript技能不是很先進。如何使用waves實時顯示剩餘時間
Wavesurfer.js提供了一個名爲getCurrentTime()的函數,但我不知道如何實現它,所以時間顯示在播放按鈕旁邊。
感謝您的幫助!
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Unbenanntes Dokument</title>
<style type="text/css">
body {
padding: 2em;
padding-top:4em;
font: "Times New Roman";
color: white;
background-color: black;
letter-spacing: -.007em;
}
titel { line-height:1.5em; padding-bottom:13em;}
.colme {
color: #B7B498
}
.subtitel {
font-style:italic;}
#maincontent {
float:left;
width:700px;
padding-right:3em;}
#sidecontent {float:left; width:300px;}
.link {font-size:1em; float:left;}
</style>
</head>
<body>
<section id="maincontent">
<titel>
<p>Lorem Ipsom<br>
</p>
</titel>
<div id="waveform"></div>
<div id="waveform-timeline"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wavesurfer.js/1.2.3/wavesurfer.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wavesurfer.js/1.2.3/plugin/wavesurfer.timeline.min.js"></script>
<script type="text/javascript">
var wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: 'white',
progressColor: 'red',
audioRate: 1,
barWidth: 3,
height: 250,
pixelRatio:1
});
wavesurfer.load('http://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasdale_64kb.mp3');
wavesurfer.on('ready', function() {
var timeline = Object.create(WaveSurfer.Timeline);
timeline.init({
wavesurfer: wavesurfer,
container: '#waveform-timeline'
});});
</script>
<button onClick="wavesurfer.playPause()">
Play
</button>
<span style="padding-left:3em; font-family:Arial; font-size:0.8em;"> Recorder in 2016</span>
</section>
<div id="sidecontent">
<p>where</p>
</div>
<div style="clear:both"> </div>
</body>
</html>
獲取總時間,並減去當前時間 – Feathercrown