Tuesday, 15 May 2012

html5 - Trying to play audio using JavaScript. But is not playing? -



html5 - Trying to play audio using JavaScript. But is not playing? -

so trying create radio station project fun. in start play sound file saying like: "welcome beat @ 97.5" or whatever , take random song , after ends play sound file saying "that awesome beat. moving on next!" , play different random song

exciting part! code! tried doing this:

var sound = new audio("test.mp3"); audio.play();

it wouldnt play anything? whats easiest , fastest way play sound javascript? please no html involved.

edit: tried utilize howler.js wouldnt still? here code:

//i moved var sound = new howl({ urls: ['/audio/test.mp3'] }).play();

this directory: c:\websites\infiniteradiostation\audio\test.mp3

the code have posted looks good, please check javascript console there no errors , create sure path of file correct.

other have multiple options can utilize enhance functionality.

soundmanager2

soundmanager2 first-class library provides tons of features(and backward compatibility if prefer).

the sample code this.

<script src="/path/to/soundmanager2.js"></script> <script> soundmanager.setup({ url: '/path/to/swf-files/', onready: function() { var mysound = soundmanager.createsound({ id: 'asound', url: '/path/to/an.mp3' }); mysound.play(); } }); </script> howler.js

howler first-class library thats worth looking.its illustration code thing this

var sound = new howl({ urls: ['sound.mp3', 'sound.ogg', 'sound.wav'], autoplay: true, loop: true, volume: 0.5, onend: function() { alert('finished!'); } });

javascript html5 audio playback

No comments:

Post a Comment