What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

Play section of sound file?

giomach

New member
Joined
Oct 30, 2024
Messages
2
Reaction score
0
HTML Coins
0
In a webpage I'm using the audio tag to play a sound file from a remote server. <audio controls autoplay><source src="https://www. ........ .mp3" type="audio/mpeg"></audio>

But in some cases I don't want to play the whole of the remote file, just a part of it. If the audio tag had start and end attributes, and the controls showed the data relevant to the chosen section, that would be perfect, but it seems it isn't possible.

What would be the best way to go about this?

It would be easy to capture the sound file and extract the bit I want to a local file, but I think the copyright will not allow this.
 
After some web searching, I've got as far as this:

<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 rté archivesat 2:00 rather than resuming at 3:00

Any hints welcome!
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back