469,081 Members | 1,573 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,081 developers. It's quick & easy.

Start play of Object sound in MZ

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
Jul 23 '05 #1
6 3815
On Wed, 22 Dec 2004 10:36:55 +1100, Andrew Poulos wrote:
document.getElementById("playButton").onclick = function() {
audObj.Play();


Try the lowercase version (untested)..

audObj.play();

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Jul 23 '05 #2
Andrew Thompson wrote:
On Wed, 22 Dec 2004 10:36:55 +1100, Andrew Poulos wrote:

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

Try the lowercase version (untested)..

audObj.play();


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

Andrew Poulos
Jul 23 '05 #3
On Wed, 22 Dec 2004 11:30:51 +1100, Andrew Poulos <ap*****@hotmail.com>
wrote:

[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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
Michael Winter wrote:
On Wed, 22 Dec 2004 11:30:51 +1100, Andrew Poulos <ap*****@hotmail.com>
wrote:

[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
Jul 23 '05 #5


Andrew Poulos wrote:
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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #6
Martin Honnen wrote:


Andrew Poulos wrote:
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.


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
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by minchu | last post: by
1 post views Thread by Lam | last post: by
3 posts views Thread by illmagination | last post: by
9 posts views Thread by =?Utf-8?B?anVhbg==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.