admin管理员组文章数量:1406042
Im playing some HTML5 audio using the Howler.js library.
Currently im able to determine the total length of the audio file with sound.duration();
however im not sure how to create a timer to show how much time that has been played.
I create a simple sound object like so:
var sound = new Howl({
src: ['sound.ogg', 'sound.mp3', 'sound.wav'],
autoplay: true,
loop: false,
volume: 1,
onload: function() {
var totalSoundDuration = sound.duration();
},
onplay: function(getSoundId) {
//sound playing
},
onend: function() {
//sound play finished
}
});
I can't seem to find any method within the library (?) to check for currentTime so I can update my timer function.
An alternative route could simply be to trigger/toggle a setInterval upon onplay:
like:
var currentTimeTracker=setInterval(function () {myTimer()}, 1000);
function myTimer() {
timePlayed++;
$("#time" ).html(timePlayed);
}
Not sure if that would be a good approach? Any suggestions?
Howler.js ref: .js/tree/2.0#global-core-properties
Im playing some HTML5 audio using the Howler.js library.
Currently im able to determine the total length of the audio file with sound.duration();
however im not sure how to create a timer to show how much time that has been played.
I create a simple sound object like so:
var sound = new Howl({
src: ['sound.ogg', 'sound.mp3', 'sound.wav'],
autoplay: true,
loop: false,
volume: 1,
onload: function() {
var totalSoundDuration = sound.duration();
},
onplay: function(getSoundId) {
//sound playing
},
onend: function() {
//sound play finished
}
});
I can't seem to find any method within the library (?) to check for currentTime so I can update my timer function.
An alternative route could simply be to trigger/toggle a setInterval upon onplay:
like:
var currentTimeTracker=setInterval(function () {myTimer()}, 1000);
function myTimer() {
timePlayed++;
$("#time" ).html(timePlayed);
}
Not sure if that would be a good approach? Any suggestions?
Howler.js ref: https://github./goldfire/howler.js/tree/2.0#global-core-properties
Share Improve this question asked Dec 15, 2014 at 10:50 user1231561user1231561 3,3598 gold badges41 silver badges57 bronze badges1 Answer
Reset to default 2According to http://goldfirestudios./blog/104/howler.js-Modern-Web-Audio-Javascript-Library sound.pos()
should get the current position. The pos
method can get or set, depending on whether you pass through the optional position
parameter.
本文标签: javascriptHTML5 audioget time played of a sound object (howlerjs)Stack Overflow
版权声明:本文标题:javascript - HTML5 audio - get time played of a sound object (howler.js) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744966036a2634952.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论