问题
I want to create custom player with 10 sounds for example. All 10 tracks are components of one music composition, created by different instruments.
For each track I want to have on/off switcher. After clicking each switcher sounds will play.
After turning on of all buttons all tracks have to be played in the same time.
Each track have to be repeated again and again after finishing. Is it possible to make this without flash?
This is example of this task, created in ActionScripts: http://www.incredibox.com/en/play#
Thanks!
回答1:
It is possible with HTML5 Audio API.
See this getting started tutorial: http://www.html5rocks.com/en/tutorials/webaudio/intro/
Here is an excellent library to start with: http://www.createjs.com
and some examples: http://www.createjs.com/#!/SoundJS/demos
as well as the official spec: https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html
回答2:
Using the HTML5 javascript audio API, you can instantiate as many audio objects as you like:
var soundOne = new Audio('sound1.ogg'),
soundTwo = new Audio('sound2.ogg'),
soundThree = new Audio('sound3.ogg');
// etc.
You can then play and stop them programatically. E.g. soundOne.play();
Check out https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
For looping, there is a loop directive, but it's not widely supported. Check out this SO article for a work around: HTML5 Audio Looping
来源:https://stackoverflow.com/questions/17892565/is-it-possible-to-create-javascript-audio-player-with-multiple-tracks-playing-in