11-21-2012 09:57 PM
I can't seem to get HTML5 audio (.wav) to loop.
var bgaudio = document.createElement("audio");
bgaudio.src="sounds/background.wav";
bgaudio.loop = true;
bgaudio.play();It plays one time, but doesn't loop. Am I doing something wrong?
I even tried putting in an audio tag in HTML
<audio id="audiobg1" preload> <source src="sounds/background.wav"> </audio>
with the following Javascript:
document.getElementById('audiobg1').addEventListen er('ended', function(){
this.currentTime = 0;}, false);
document.getElementById('audiobg1').play();Still.. plays once but doesn't loop. I do have other sound playing but they have their own ID.
Any clue? Using Webworks with BBUI.js
Thanks.
11-22-2012 11:20 AM
Hi there,
Which device/OS version are you testing on? My approach is generally as follows:
var track = document.createElement('audio');
track.setAttribute('src', 'audio/myfile.mp3');
track.setAttribute('preload', 'auto');
track.setAttribute('loop', 'true');
track.setAttribute('autoplay', 'true'); /* Optional. */
track.load();
The key difference is making the settings through the setAttribute function. I've had success with this in the past, cna you give it a shot and let me know how it goes?
11-22-2012 12:41 PM
It didn't work in Ripple and on the Dev Alpha A (latest OS). I will try out your code and see if that works.
Thank you.
11-23-2012 10:15 PM
Hi Erik,
Tried out your code with my sound file. Didn't work. ![]()
I tried changing the file format to .mp3 (mine was a .wav), also didn't work.
I tried it without having any other audio channel in play. No loop. It just ends. STRANGE.
11-26-2012 11:02 AM
I'll hack together a sample and will share it here (assuming I can get it working.)
11-26-2012 06:27 PM - edited 11-26-2012 06:29 PM
Hello again,
Here is a sample index.html file that I am running in Ripple and successfully hearing my audio track looping. The audio starts to play once Ripple is loaded and the window content is fully populated.
<!DOCTYPE html>
<html>
<head></head>
<body>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
if (typeof blackberry !== 'undefined') {
var track = document.createElement('audio');
track.setAttribute('src', 'audio.mp3');
track.setAttribute('preload', 'auto');
track.setAttribute('loop', 'true');
track.setAttribute('autoplay', 'true');
track.load();
}
}, false);
</script>
</body>
</html>
11-26-2012 07:16 PM - edited 11-26-2012 07:18 PM
Thanks Erik, I am going to give it a try. It haven't tried it with just straight HTML5. I have it with BBUI.js.
Can you wrap it with BBUI.js? It would trigger Webworks + BBUI.js which could be causing the problem.
11-27-2012 03:43 AM - edited 11-27-2012 03:44 AM
Hi Erik,
Thank you for all your help and the code posting. It didn't work,,, and it wasn't because of your code (and perhaps mine also). It has something to do with the Ripple Services. It turns out that HTML5 Audio looping doesn't work on http://localhost:9910 .
I simplify it to just
<audio controls autoplay loop> <source src="music.wav" type="audio/wav" /> </audio>
It wouldn't loop when I play it on http://localhost:9910 (Ripple Services).
Tried it on IIS, http://localhost, and it would play with loop (without Ripple). Enabled Ripple and it would work with looping*.
*Strange part is if I run an app that I used to have on the Ripple Services directory on the IIS folder, I would lose all sound. Looking at the Developer Mode / Network tab it looks like it was trying to "GET" the sound but was cancelled.
Fustrating and I hope the new updates would fix it.
11-27-2012 12:26 PM
11-30-2012 08:25 AM
Hello
I have a similar problem. I just found that using the ripple extension for Chrome I can get to listen my live .m3u in ripple, after playing it alone without Ripple. However it seems not to work in any other case and even when I´m packaging my app, Ripple warns me that Blackberry.audio feature is not found.
Any advice?
Thanks in advance!
R.