> Jason Weathersby gave me the first clue. His example uses canplaythrough, 
> which doesn't fire until all the audio is loaded. The purpose of canplay is 
> to indicate you can start playing but you need more buffering. Maybe canplay 
> is not supported on the phone even though it works in the desktop browsers.

canplay event is not the precondition of audio.play(), you can set the autoplay 
attribute
to let the audio tag play after the file is loaded, then this will not be a 
problem and
the code is simpler. Just set src then the audio tag will play.

> Does any music play in the simulator (what I'm using)? WAV, OGG, MP3?

OGG should play in the simulator but not for WAV and MP3.

> Thanks for the help. I'm making progress. Right now I'm still trying to 
> figure out the difference between 
>    myAudio = new Audio("song.wav"); 
> and 
>        // Create audio object.
>        myAudio = document.createElement("audio");
>        myAudio.src = "oggsong.ogg";
>        myAudio.src = "mp3song.mp3";

Why you need to set the src twice here?

> Do I need to append the audio to the body? Does it hurt?

No, like an img or video tag you don't need to append the it to the DOM tree
if you just want to play the sound.

- Dominic


----- Original Message -----
From: "Bob Thulfram" <[email protected]>
To: [email protected]
Sent: Tuesday, December 10, 2013 5:21:29 PM
Subject: Re: [b2g] Need simple help with audio

On Monday, December 9, 2013 6:49:07 PM UTC-8, Bob Thulfram wrote:
> Or maybe audio isn't simple anymore. All I want to do is play an audio file.
> 
> 
> 
> Here's my code:
> 
> 
> 
> <!DOCTYPE HTML>
> 
> <html>
> 
>   <head>
> 
>     <meta charset="utf-8">
> 
>     <title>
> 
>       Audio Test
> 
>     </title>
> 
>       
> 
>       <script>
> 
> 
> 
>       // Load the page.
> 
>       window.addEventListener("load", 
> 
>         runFirst, false);
> 
>         
> 
>    
> 
>       // Runs when the page is loaded.
> 
>       function runFirst() {
> 
>       
> 
>         console.log("page loaded");
> 
>       
> 
>         // Create audio object.
> 
>         myAudio = document.createElement("audio");
> 
>         myAudio.src = "oggsong.ogg";
> 
>         myAudio.src = "mp3song.mp3";
> 
>         myBody.appendChild(myAudio);
> 
>         
> 
>         // What did we load?
> 
>         console.log(myAudio.src);
> 
>         
> 
>         // Wait until we can play.
> 
>         myAudio.addEventListener("canplay",
> 
>           processAudio, false);  
> 
>       }
> 
>  
> 
>       // Called when audio is ready to play.
> 
>       function processAudio() {        
> 
> 
> 
>         // Stop the event firing.
> 
>         myAudio.removeEventListener("canplay", processAudio);
> 
>           
> 
>         console.log("audio loaded");
> 
>         
> 
>         // Stop the audio temporarily
> 
>         myAudio.pause();
> 
>         
> 
>         // Sets the position to play from.
> 
>         myAudio.currentTime = 10;
> 
>         
> 
>         // How long is the audio?
> 
>         console.log(myAudio.duration);
> 
>         
> 
>         // Play the audio.
> 
>         myAudio.play();
> 
>           
> 
>       }
> 
>        
> 
>        </script>
> 
>     </head>
> 
>     
> 
>     <body id="myBody">
> 
>     </body>
> 
> 
> 
> </html>
> 
> 
> 
> This plays the song in Firefox 27, IE 11, and Chrome #whocares. But when I 
> put it on my ZTE Open, no sound.
> 
> 
> 
> Here's my manifest:
> 
> 
> 
> {
> 
>   "name": "Little Audio",
> 
>   "description": "Playing audio",
> 
>   "launch_path": "/index.html",
> 
>   "icons": {
> 
>     "60":  "/icons/icon-60.png",
> 
>     "128": "/icons/icon-128.png"
> 
>   },
> 
>   "developer": {
> 
>     "name": "Your Name",
> 
>     "url": "http://www.yourwebsite.com";
> 
>   },
> 
>   "default_locale": "en"
> 
> }
> 
> 
> 
> I have two questions:
> 
> 
> 
> 1. What am I doing wrong? Is the manifest wrong? Do I need to specify the 
> music loaded in the manifest. The music is in the same folder level as 
> index.com.
> 
> 
> 
> 2. I've noticed that the ogg file doesn't load in Firefox. Is Firefox now 
> supporting MP3? I put the ogg file first, thinking that Firefox might like 
> it, but maybe it doesn't love ogg any longer?
> 
> 
> 
> I'm loading this onto the phone through the USB cable, so it should have the 
> permissions. Any clues would be great. This is frustrating because it works 
> on all the other browsers. Thanks!
> 
> 
> 
> PS: I know WebAudio is better, but I'd like to get HTML5 Audio working on 
> Firefox OS. I'll write about it in my blog if I can get some clues.

Jason Weathersby gave me the first clue. His example uses canplaythrough, which 
doesn't fire until all the audio is loaded. The purpose of canplay is to 
indicate you can start playing but you need more buffering. Maybe canplay is 
not supported on the phone even though it works in the desktop browsers.

Does any music play in the simulator (what I'm using)? WAV, OGG, MP3?

Thanks for the help. I'm making progress. Right now I'm still trying to figure 
out the difference between 

    myAudio = new Audio("song.wav"); 

and 

        // Create audio object.
        myAudio = document.createElement("audio");
        myAudio.src = "oggsong.ogg";
        myAudio.src = "mp3song.mp3";
        myBody.appendChild(myAudio);

Do I need to append the audio to the body? Does it hurt?

Also, I thought that onXXX wasn't supported, but it seems to work. I prefer 
event handlers.   
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g

Reply via email to