In a webpage I'm using the HTML audio tag to play a sound file from a remote server.
But in some cases I don't want to play the whole of the remote file, just a part of it. It would be easy to capture the remote file and extract the bit I want to my own website, but I think the copyright will not allow this.
If the audio tag had start and end attributes, that would be perfect, but it hasn't, so I'm trying to do it with javascript, about which I know very little. After some web searching, I've got as far as this:
This will play the section from 2 mins to 3 mins (values just for demo purposes), which is what I want.
What remains to be done is to get the displayed controls to relate to the section rather than to the whole sound file. Specifically:
• show the start time as 0:00 rather than 2:00
• show the end time as 1:00 rather than 14:35 (which is the length of the whole sound file)
• make the progress slider relate to the section from 2:00 to 3:00
• after playback finishes, ensure clicking the play button restarts playing at 2:00 rather than continuing from 3:00
How can I access the "properties" of the audio.controls thing?
Any hints welcome!
But in some cases I don't want to play the whole of the remote file, just a part of it. It would be easy to capture the remote file and extract the bit I want to my own website, but I think the copyright will not allow this.
If the audio tag had start and end attributes, that would be perfect, but it hasn't, so I'm trying to do it with javascript, about which I know very little. After some web searching, I've got as far as this:
HTML:
<audio id="sample" controls src="https://....../example.mp3" preload></audio><br><br>
<script>
var audio = document.getElementById('sample');
audio.currentTime = 120.0;
audio.play();
int = setInterval(function()
{if (audio.currentTime > 180.0) {audio.pause(); clearInterval(int); } },
10);
</script>
This will play the section from 2 mins to 3 mins (values just for demo purposes), which is what I want.
What remains to be done is to get the displayed controls to relate to the section rather than to the whole sound file. Specifically:
• show the start time as 0:00 rather than 2:00
• show the end time as 1:00 rather than 14:35 (which is the length of the whole sound file)
• make the progress slider relate to the section from 2:00 to 3:00
• after playback finishes, ensure clicking the play button restarts playing at 2:00 rather than continuing from 3:00
How can I access the "properties" of the audio.controls thing?
Any hints welcome!