Hi Bob,
> 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.
Your code looks reasonable, but you better not to count on the canplay event
to play the music, you can just call play() after you set the src, and if it's
not playable, then it should just fire error which you can also listen to it
and handle the rest. I guess it might because the canplay event was not fired
so your audio tag did not play.
You don't need to specify the music you need in the manifest, unless you want
to load some music from the storages, then you will need:
"device-storage:music":{ "access": "readonly" }" in the manifest to get the
access of music.
Are you using the Firefox OS simulator to install your app onto the device?
(https://developer.mozilla.org/en-US/docs/Tools/Firefox_OS_Simulator)
There is a manifest validation and you can use it to check your manifest.
Also try to run it on the simulator first, if it works on simulator, then
it should work on the device as well.
> 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?
The latest Firefox OS simulator does not support the MP3, but I think you
should be able to play it if it runs on the real device, so if you are still
developing, you can use ogg files first then replace them after you got your
app work.
- Dominic
----- Original Message -----
From: "Bob Thulfram" <[email protected]>
To: [email protected]
Sent: Tuesday, December 10, 2013 10:49:07 AM
Subject: [b2g] Need simple help with audio
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.
_______________________________________________
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