Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Audio display only play pause and mute buttons

I'm wondering if there's a quick and simple way to style the HTML5 audio element to display what I want. I was wondering if you could turn certain controls on and off, but that doesn't seem to be the case.

I do not want a progress/track bar, or to display the time left. I just want a simple play/pause toggle button, and a mute/unmute toggle button.

That's all! Any ideas?

like image 214
user1380540 Avatar asked Dec 10 '12 22:12

user1380540


People also ask

How to add audio in HTML5?

HTML Audio - How It Works. The controls attribute adds audio controls, like play, pause, and volume. The <source> element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format. The text between the <audio> and </audio> tags will only be displayed in browsers that do not ...

Is it possible to mute audio after AutoPlay?

However, muted autoplay is always allowed. Add muted after autoplay to let your audio file start playing automatically (but muted): Your browser does not support the audio element. The numbers in the table specify the first browser version that fully supports the <audio> element. There are three supported audio formats: MP3, WAV, and OGG.

How to play an audio file on a web page?

The HTML <audio> element is used to play an audio file on a web page. To play an audio file in HTML, use the <audio> element: Your browser does not support the audio element. The controls attribute adds audio controls, like play, pause, and volume. The <source> element allows you to specify alternative audio files which the browser may choose from.

What is the use of pause method in JavaScript?

Definition and Usage The pause () method halts (pauses) the currently playing audio. Tip: This method is often used together with the play () method. Tip: Use the controls property to display audio controls (like play, pause, seeking, volume, etc, attached on the audio).


2 Answers

Use this code it will serve your purpose.

<!DOCTYPE html>
<html>
<body>
 <audio id="player" src="horse.ogg"></audio>
<div>
    <button onclick="document.getElementById('player').play()">Play</button>
    <button onclick="document.getElementById('player').pause()">Pause</button>
    <button onclick="document.getElementById('player').muted=!document.getElementById('player').muted">Mute/ Unmute</button>
</div>
</body>
</html>
like image 122
Mohd. Umar Avatar answered Sep 20 '22 17:09

Mohd. Umar


You could use the Media API and build your own set of controls with the functionality you want. I've written about this: Working with HTML5 multimedia components – Part 3: Custom controls - which shows a video example, but you can just as easily build an audio one.

like image 32
Ian Devlin Avatar answered Sep 20 '22 17:09

Ian Devlin