`
wjlgryx
  • 浏览: 308466 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

HTML5 Audio Loops

阅读更多

One of the neatest things about HTML5 is support for the new <audio> tag. Like <video> it allows you to natively support media in good browsers like Chrome, FireFox, Opera and Safari. Add a touch of JavaScript and a new era of  media applications become possible.

Synthesizers, music trackers and games require seamless audio loops though so we need something a bit simpler for our first foray into HTML5 audio.

Oooh, how about a retro beatbox with individual track adjustments (start/stop/loop/volume) that could be used to build a unique soundscape from many separate instruments. Perfect!

Fantasy can only become reality through hard work so let’s get started with some tests first.

Loop Method 1


Uses the ‘loop’ property.

<audio id="audio_1" controls preload loop>
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.ogg">
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.wav">
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.mp3">
</audio>

Loop Method 2


Uses a JavaScript function to loop when an ‘ended’ event is called.

<audio id="audio_2" controls preload>
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.ogg">
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.wav">
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.mp3">
</audio>
document.getElementById('audio_2').addEventListener('ended', function(){
this.currentTime = 0;
}, false);

Loop Method 3


Uses two JavaScript functions and two audio elements with the same source to alternate playback duties.

<audio id="audio_3" controls preload>
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.ogg">
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.wav">
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.mp3">
</audio>
<audio id="audio_4" controls preload>
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.ogg">
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.wav">
	<source src="/wp-content/uploads/2010/04/html5-audio-loop.mp3">
</audio>
document.getElementById('audio_3').addEventListener('ended', function(){
this.currentTime = 0;
this.pause();
document.getElementById('audio_4').play();
}, false);

document.getElementById('audio_4').addEventListener('ended', function(){
this.currentTime = 0;
this.pause();
document.getElementById('audio_3').play();
}, false);

Browser Support

Tests were done on Windows 7 with Chrome 5.0.342.9 beta, FireFox 3.6.3, Internet Explorer 9.0 Preview, Opera 10.51 and Safari 4.0.5.

Chrome seems to trigger loops before the current sound is completely finished leading to some odd jumpiness. All loop methods are affected.

FireFox doesn’t seem to like the ‘loop’ property of method 1, odd. Method 2 has the slightest of delays between loops and method 3 was actually perfect! I didn’t believe it until verification at the millisecond level with Audacity. Hooray Mozilla!

Internet Explorer 9 doesn’t support the audio tag yet. Hopefully it will before an official release.

Opera performs almost as well as FireFox although there is still a small delay even when using method 3.

Safari seems slow to start playback which is very easy to detect once you hear a loop. All loop methods affected.

Feedback on other browsers/OS compatibility would be very interesting so please feel free to discuss any findings in the comments below.

Final Thoughts

As of right now (April 11, 2010) only FireFox can do a perfect loop by cheating a bit and using two <audio> elements with JavaScript.

So yeah, it’s a bit too early for HTML5 audio loops but don’t let that stop you from creating sound boards, media players and other fun things.

Hopefully with some more optimizations audio support will continue to improve and a HTML5 beatbox fantasy can become reality.

Until then there are plenty of other fun things to play with.

Cheers!

分享到:
评论

相关推荐

    [Apple官方] Apple Loops Audio

    在Apple Loops Audio中,每个循环都包含了特定的节奏、音调和时长信息,这些信息被嵌入到文件的元数据中。当你将一个Apple Loop导入到支持此格式的软件中时,无论你如何改变播放速度或音高,该循环都能保持其原始的...

    Dealing with Audio Ground Loops

    5. 尝试使用滤波器,如电源线滤波器或音频信号线滤波器,以去除电源或信号线中的噪声。 6. 如果条件允许,可以进行接地隔离测试,比如断开某些设备的地线连接,观察是否能改善音频质量。 解决音频地环回问题可能...

    Designing Control Loops for Linear and Switching Power Supplies英

    Christophe Basso先生的《Designing Control Loops For Linear and Switching Power Supplies》 关电源 环路控制 零点 极点 在开关模式的功率转换器中,功率开关的导通时间是根据输入和输出电压来调节的。因而,功率...

    Designing Control Loops for Linear and Switching Power Supplies

    Readers also find coverage of the underpinnings and principles of control loops so they can gain a more complete understanding of the material. This authoritative volume explains how to conduct ...

    Loops,Kknots, Gauge Theories and Quantum Gravity

    Loops,Kknots, Gauge Theories and Quantum Gravity Loops,Kknots, Gauge Theories and Quantum Gravity Loops,Kknots, Gauge Theories and Quantum Gravity

    Phase-Locked Loops Design Simulation and Applications

    相位锁定环(Phase-Locked Loops, PLLs)设计与仿真 #### 定义与原理 相位锁定环(PLL)是一种用于控制两个信号之间的相位差的技术。在射频(RF)系统中,PLL被广泛应用于频率合成、时钟恢复以及其他需要精确控制频率...

    For Loops.ipynb

    For Loops.ipynb

    Razavi_Monolithic_Phase-Locked_Loops_and_Clock_Recovery_Circuits 2

    Razavi_Monolithic_Phase-Locked_Loops_and_Clock_Recovery_Circuits 第二部分

    Phaes-Locked Loops Design R.E.Best

    CD-Rom for the book "Phase-Locked Loops Design,Simulation and Applications by R.E.Best. A design program for Phase-locked loops circuits

    DESIGN OF CMOS PHASE‑LOCKED LOOPS

    Analog Phase-Locked Loops: A Tutorial.** 对PLL的基本原理和设计方法进行了深入浅出的讲解。 通过上述内容的综述,我们可以看出,CMOS PLL设计是一项复杂的工程任务,需要综合考虑多个方面的因素才能实现高性能...

    模拟集成电路的分析与设计:Chapter 15-Phase-Locked Loops.ppt

    模拟集成电路的分析与设计:Chapter 15-Phase-Locked Loops.ppt

    Razavi_Monolithic_Phase-Locked_Loops_and_Clock_Recovery_Circuits 3

    Razavi_Monolithic_Phase-Locked_Loops_and_Clock_Recovery_Circuits 第三部分

    Phase Lock Loops and Frequency Synthesis

    ### 锁象环与频率合成 #### 一、锁象环(PLL)基础概念 锁象环(Phase-Locked Loop,简称PLL)是一种用于稳定、调整信号相位和频率的电子电路。它由三个主要部分组成:鉴相器(Phase Detector)、压控振荡器...

    eac3to V3.17

    * for gaps, edits & repairs &lt; 1000ms eac3to now loops audio by default * option "-silence" forces eac3to to insert silence instead of looping audio * option "-loop" forces eac3to to loop audio instead...

    锁相环 锁相环(PLL: Phase-locked loops)是一种利用反馈(Feedback)控制

    锁相环(PLL: Phase-locked loops)是电子工程领域中一种重要的同步系统,它主要用于在通信、计测和数字信号处理等应用中实现精确的频率和相位控制。其核心理念是通过反馈机制使系统输出信号的相位与外部参考信号保持...

    fruity loops kick

    nice fx fruity loops music house music eric pridz

    Run Loops.pdf

    iOS Runloop官方文档翻译.Run loops 是线程相关的的基础框架的一部分。一个 run loop 就是一个事件处理 的循环,用来不停的调度工作以及处理输入事件。使用 run loop 的目的是让你的线 程在有工作的时候忙于工作,...

    phase-locked loops:design,simulation and applications sixth

    ### 锁相环(PLL)的设计、仿真及应用概述 #### 一、锁相环(PLL)简介 锁相环(Phase-Locked Loop,PLL)是现代电子技术中不可或缺的一部分,广泛应用于通信系统、计算机系统、音频/视频处理等多个领域。...

Global site tag (gtag.js) - Google Analytics