[英]How to display time from a media played from the javascript file, into a html file
I have a mp3 located inside cordova.file.dataDirectory; 我在cordova.file.dataDirectory内部有一个mp3;
I'm playing it through the javascript file with media.play(); 我正在使用media.play()通过javascript文件播放它; when the user presses the play button.
当用户按下播放按钮时。 I now wan't to display the time (how much seconds the media is already played.)
我现在不想显示时间(媒体已经播放了多少秒。)
This is not my complete code just assume that the media is played. 这不是我的完整代码,只是假设媒体已播放。
media.play();
media.ontimeupdate = function() {myFunction()};
function myFunction() {
// Display the current position of the mp3 in a p element with id="time"
document.getElementById("time").innerHTML = media.currentTime;
}
I want to display the time inside the html here: 我想在html中显示时间:
<p>Playback position:<span id="time"></span></p>
Thank's in advance. 提前致谢。
Write this code after playing the media 播放媒体后编写此代码
if (mediaTimer == null) {
mediaTimer = setInterval(function() {
media.getCurrentPosition(
function(position) {
if (position > -1) {
document.getElementById("time").innerHTML = position;
}
},
function(e) {
document.getElementById("time").innerHTML = "Error";
}
);
}, 1000);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.