简体   繁体   English

如何显示从javascript文件播放的媒体到html文件的时间

[英]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.

相关问题 媒体结束时如何调用函数(从javascript文件播放) - How to call a function when the media has ended, which is played from the javascript file 如何从HTML5音频播放器获取播放时间? - How to get the played time from HTML5 audio player? 如何防止用户滚动到页面的一部分,直到播放了一定时间的音频文件? - How to keep user from scrolling to portion of a page until an audio file has played for certain amount of time? 如何使用媒体查询从HTML加载javascript文件 - How can I use media-queries to load a javascript file from HTML 如何在javascript中显示一个html文件? - How to display an html file in javascript? 如何从javascript文件中的函数中获取变量,并在单独的文件中使用html显示 - How to take a variable from a function in a javascript file, and display it with html in a seperate file 如何使用香草JavaScript从用户的媒体文件中获取频率? - How to get frequency from user's media file with vanilla javascript? 如何显示离子的Javascript文件中的数据? - How to display data from a Javascript file in ionic? 如何显示JavaScript文件中的方法名称 - How to display methods name from a JavaScript file 如何显示Javascript文件中的所有元素 - How to display all elements from a Javascript file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM