Help
Difference between revisions of "Embed audio in HTML"
Line 17: | Line 17: | ||
* https://howlerjs.com | * https://howlerjs.com | ||
− | === Using HTML5 audio === | + | === Using minimal HTML5 audio === |
<pre> | <pre> | ||
<audio controls="controls"> | <audio controls="controls"> | ||
Line 28: | Line 28: | ||
;References | ;References | ||
* https://www.w3schools.com/tags/tag_audio.asp | * https://www.w3schools.com/tags/tag_audio.asp | ||
+ | |||
+ | === Using HTML5, Jquery.js and Bootstrap.css === | ||
+ | <pre> | ||
+ | <div class="audio"> | ||
+ | <audio id="" preload="auto"> | ||
+ | <source src="https://upload.wikimedia.org/wikipedia/commons/3/3d/Africanagogosound.ogg" type="audio/ogg"> | ||
+ | Your browser does not support HTML5 audio. | ||
+ | </audio> | ||
+ | |||
+ | <button class="btn btn-primary"> | ||
+ | <span class="play"><text>⏵</text></span> | ||
+ | </button> | ||
+ | <button class="btn btn-info" style="display:none;"> | ||
+ | <span class="pause"><text>⏸</text></span> | ||
+ | </button> | ||
+ | </div> | ||
+ | <script>var waitTime = 150; | ||
+ | var playItemToggle = function(item) { | ||
+ | setTimeout(function () { | ||
+ | if (item.paused) { /*item.load();*/ item.play() } | ||
+ | else { item.pause(); } | ||
+ | }, waitTime); | ||
+ | } | ||
+ | |||
+ | $('.audio').on('click', function() { | ||
+ | var $audio = $(this).find('audio')[0], | ||
+ | $btns = $(this).find('.btn'); | ||
+ | $btns.toggle(); | ||
+ | playItemToggle($audio); | ||
+ | });</script> | ||
+ | </pre> | ||
+ | |||
+ | ;Example | ||
+ | * https://codepen.io/anon/pen/pVqxyW | ||
+ | * https://www.w3schools.com/tags/ref_av_dom.asp | ||
+ | |||
+ | === Audio controls characters === | ||
+ | * ⏩ <code>&#x23e9;</code> | ||
+ | * ⏪ <code>&#x23ea;</code> | ||
+ | * ⏫ <code>&#x24eb;</code> | ||
+ | * ⏬ <code>&#x23ec;</code> | ||
+ | * ⏭ <code>&#x23ed;</code> | ||
+ | * ⏮ <code>&#x23ee;</code> | ||
+ | * ⏯ <code>&#x23ef;</code> | ||
+ | * ⏴ <code>&#x23f4;</code> | ||
+ | * ⏵ <code>&#x23f5;</code> | ||
+ | * ⏶ <code>&#x23f6;</code> | ||
+ | * ⏷ <code>&#x23f7;</code> | ||
+ | * ⏸ <code>&#x23f8;</code> | ||
+ | * ⏹ <code>&#x23f9;</code> | ||
+ | * ⏺ <code>&#x23fa;</code> | ||
+ | See [https://stackoverflow.com/questions/22885702/html-for-the-pause-symbol-in-a-video-control HTML symbol in audio and video controls] |
Revision as of 14:36, 19 May 2018
Given an audio file Bazinga.mp3
.
Using Howler JS
- HTML
<script src="./howler-2.0.8.js"></script> <buton id="bazingaId" class="audio">Bazinga</button>
- Javascript
$('.audio').on('click', function() { var sound = new Howl({ src: [ '/to/folder/Bazinga.mp3','/to/folder/Bazinga.ogg' ]}); sound.play(); });
- References
Using minimal HTML5 audio
<audio controls="controls"> <source src="/to/folder/Bazinga.ogg" type="audio/ogg"> <source src="/to/folder/Bazinga.mp3" type="audio/mpeg"><!-- fallback --> Your browser does not support HTML5 audio. Please download and install a modern browser. </audio>
- References
Using HTML5, Jquery.js and Bootstrap.css
<div class="audio"> <audio id="" preload="auto"> <source src="https://upload.wikimedia.org/wikipedia/commons/3/3d/Africanagogosound.ogg" type="audio/ogg"> Your browser does not support HTML5 audio. </audio> <button class="btn btn-primary"> <span class="play"><text>⏵</text></span> </button> <button class="btn btn-info" style="display:none;"> <span class="pause"><text>⏸</text></span> </button> </div> <script>var waitTime = 150; var playItemToggle = function(item) { setTimeout(function () { if (item.paused) { /*item.load();*/ item.play() } else { item.pause(); } }, waitTime); } $('.audio').on('click', function() { var $audio = $(this).find('audio')[0], $btns = $(this).find('.btn'); $btns.toggle(); playItemToggle($audio); });</script>
- Example
Audio controls characters
- ⏩
⏩
- ⏪
⏪
- ⏫
⓫
- ⏬
⏬
- ⏭
⏭
- ⏮
⏮
- ⏯
⏯
- ⏴
⏴
- ⏵
⏵
- ⏶
⏶
- ⏷
⏷
- ⏸
⏸
- ⏹
⏹
- ⏺
⏺