How to start playback of audio from a specific time point?
let suppose an audio is playing, you reload the page and the audio should resume from that point where the page was reloaded. I already have code storing the time as audio plays, but I don't know how to use that value as new audio start time.
li = $('#plList li').click(function () {
var id = parseInt($(this).index());
if (id !== index) {
playTrack(id);
}
}),
loadTrack = function (id) {
$('.plSel').removeClass('plSel');
$('#plList li:eq(' + id + ')').addClass('plSel');
npTitle.text(tracks[id].name);
index = id;
audio.src = mediaPath + tracks[id].file + extension;
// Assign an ontimeupdate event to the video element, and execute a function if the current playback position has changed
audio.ontimeupdate = function() {myFunction()};
function myFunction()
{
// Display the current position of the audio.
$('#cookieVal').val(audio.currentTime);
localStorage.setItem("audioPlayTime", audio.currentTime);
console.log(audio.currentTime);
}
},
playTrack = function (id) {
loadTrack(id);
audio.play();
};
extension = audio.canPlayType('audio/mpeg') ? '.mp3' : audio.canPlayType('audio/ogg') ? '.ogg' : '';
loadTrack(index);
}