Start play of Object sound in MZ

A

Andrew Poulos

As a follow on to the 'fun' I had with IE I'm now trying to play sounds
using an Object tag (no Embed) in MZ. Sadly whenever 'playButton' gets
clicked MZ says that "audObj.Play is not a function":

window.onload = function() {
var audObj = document.createElement("object");
audObj.setAttribute("id", "objmedia");
audObj.setAttribute("type","audio/x-aiff");
audObj.setAttribute("data","media/aif_sample.aif");

audParam = document.createElement("param");
audParam.setAttribute("name","AutoStart");
audParam.setAttribute("value","false");
audObj.appendChild(audParam);

document.body.appendChild(audObj);

document.getElementById("playButton").onclick = function() {
audObj.Play();
//document.getElementById("objmedia").Play();
}
}


If I change AutoStart to 'true' then the audio starts playing so this
implies that the sound gets load correctly. Is there a way to get
playing to start with a mouse click?

Andrew Poulos
 
M

Michael Winter

[snip]
Tried it and various other words (start, DoPlay, run,...) no joy.

I'd expect Mozilla to only expose the standard properties of an OBJECT
element unless perhaps a plug-in was involved, though I could be wrong.

Mike
 
A

Andrew Poulos

Michael said:
[snip]
Tried it and various other words (start, DoPlay, run,...) no joy.


I'd expect Mozilla to only expose the standard properties of an OBJECT
element unless perhaps a plug-in was involved, though I could be wrong.

Mike
I was kind of afraid of that.

Instead of trying to call an non-existent Play property, I could delete
the child and then create a new OBJECT element with AutoStart set to
true. As the sound file has already been downloaded it should be in the
cache and therefore start playing almost immediately.

Is this an ok way to go?

Andrew Poulos
 
M

Martin Honnen

Andrew said:
As a follow on to the 'fun' I had with IE I'm now trying to play sounds
using an Object tag (no Embed) in MZ. Sadly whenever 'playButton' gets
clicked MZ says that "audObj.Play is not a function":

window.onload = function() {
var audObj = document.createElement("object");
audObj.setAttribute("id", "objmedia");
audObj.setAttribute("type","audio/x-aiff");
audObj.setAttribute("data","media/aif_sample.aif");

audParam = document.createElement("param");
audParam.setAttribute("name","AutoStart");
audParam.setAttribute("value","false");
audObj.appendChild(audParam);

document.body.appendChild(audObj);

document.getElementById("playButton").onclick = function() {
audObj.Play();
//document.getElementById("objmedia").Play();
}
}


If I change AutoStart to 'true' then the audio starts playing so this
implies that the sound gets load correctly. Is there a way to get
playing to start with a mouse click?

A plugin is going to play the audio file, not the browser itself. And if
you want to script that plugin then it needs to expose an API to the
script. Thus whether there is any method and whether it is called 'Play'
depends on the plugin registered with Mozilla for that MIME type
audio/x-aiff. Unless you know your customers have a certain plugin
installed with Mozilla and you find the documention of that plugin and
whether and what kind of method it exposes you can't build that stuff
reliably, it might indeed be more successful to create and insert an
object or embed with autostart being true whenever you want a sound to
be played. Of course even then there needs to be a plugin installed with
Mozilla to handle that MIME type thus if you want Mozilla users on
different platforms to be able to hear that sound then you need to do
some research on what sound format is well supported on different platforms.
 
A

Andrew Poulos

Martin said:
A plugin is going to play the audio file, not the browser itself. And if
you want to script that plugin then it needs to expose an API to the
script. Thus whether there is any method and whether it is called 'Play'
depends on the plugin registered with Mozilla for that MIME type
audio/x-aiff. Unless you know your customers have a certain plugin
installed with Mozilla and you find the documention of that plugin and
whether and what kind of method it exposes you can't build that stuff
reliably, it might indeed be more successful to create and insert an
object or embed with autostart being true whenever you want a sound to
be played. Of course even then there needs to be a plugin installed with
Mozilla to handle that MIME type thus if you want Mozilla users on
different platforms to be able to hear that sound then you need to do
some research on what sound format is well supported on different
platforms.

Thanks for the reply. I did some research, if you could call it that, by
googling about the internet and a number of things surprised me:
- most of the code samples are more than 5 years old
- there is no clear, standards compliant way to play sounds. Many big
company sites use an EMBED tag which is non-standard. Even Microsoft
documents a variety of ways to play sounds on Windows [yet Michael
Winter pointed out that the TYPE attribute appears not to be able to
actually be set.]
- Mozilla doesn't have a solution
- I'm tempted to put all sounds into a Flash file and then most of the
"issues" disappear, except that Flash is proprietary.
- I still have to "solve" it for a few other audio formats (and then I
have to look at video)

I wrongly imagined that these sorts of problems had been "solved" years ago.

Andrew Poulos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top