473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Playing an audio file without spawning a new window ...

Hello, I want to play an audio file embedded on my page by clicking on
an audio image and the page change to a new page. Is there a
cross-browser Javascript way to do this? Right now the code I have
is ...

<html>
<head>
<title>Dictionary: homeostasis</title>
<link href="liveink.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div class="dictionary-area">
<span class="dictionary-word">homeostasis</span>
(<span class="dictionary-pos">Noun</span>)
<br/>
<div class="dictionary-defn">The maintenance of a constant internal
state in a changing environment that is maintained by continually
making adjustments to the internal and external environment.</div>
<a href="homeostasis.mp3" target="new"><img src="audio.gif"
border="0"></a>
<div class="dictionary-close-window"><a
href="javascript:window.close()">Close Window</a></div>
</div>
</body>
</html>

The inconvenience is right now a new window is spawned to play the
audio., which contains the controller for playing the audio (complete
with pause, stop, and play buttons). All my audio clips are less than
3 seconds in length.. How can I play the audio file without launching
the controller? I don't care if there's no way to stop/pause the audio
once it's started.

Thanks for your help, - Dave

Jul 23 '05 #1
1 2644
la***********@zipmail.com wrote:
How can I play the audio file without launching
the controller? I don't care if there's no way to stop/pause the audio
once it's started.


Try this:

<html>
<head>
<title>Make some noize</title>

<script type="text/javascript">
<!--

var Sound = new Object();
Sound.play = function Sound_play(src) {
if (!src) return false;
this.stop();
var elm;
if (typeof document.all != "undefined") {
elm = document.createElement("bgsound");
elm.src = src;
}
else {
elm = document.createElement("object");
elm.setAttribute("data",src);
elm.setAttribute("type","audio/x-wav");
elm.setAttribute("controller","true");
}
document.body.appendChild(elm);
this.elm = elm;
return true;
};

Sound.stop = function Sound_stop() {
if (this.elm) {
this.elm.parentNode.removeChild(this.elm);
this.elm = null;
}
};

//-->
</script>
</head>

<body>
<div
onmouseover="Sound.play('klatschn.wav')"
onmouseout="Sound.stop()">Come over me</div>
</body>
</html>
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Schmitz | last post by:
Hi, I'm just trying to play a *.wav file, making use of the unmanaged function "sndPlaySoundA" in winmm.dll, but I still got one question: How can I avoid, that the sound file itself has to be...
7
by: Lee Moody | last post by:
I just want quick and easy way to play a .wav file out the standard sound device. It could even be as simple as activating a sound assigned to an existing windows sound event. Any suggestions?...
3
by: abrtlt | last post by:
I would like to have a web page in which, when the user clicks on any of several specific elements, a specific audio file is played, without reloading the page. The specific audio file name is...
4
by: fAnSKyer/C# newbie | last post by:
I am using winmm.dll and I found that I can't just suspend it and resume it? What should I do? Any better idea? Should I use thread? and thread.suspend will work? Thanks
2
by: peteinglastonbury | last post by:
I'd be most grateful if someone would help me. I hope I'm in the right forum (apologies if not) - I'm not sure whether my problem is CGI or Javascript related. I found a script called...
0
by: Sobin Thomas | last post by:
Hi,All... I found in one of the articles on the net that an audio file can be played in asp.net by setting the Hyperlink's Navigate Url as the audio file name. ie,...
0
by: Sobin Thomas | last post by:
Hi,All... I found in one of the articles on the net that an audio file can be played in asp.net by setting the Hyperlink's Navigate Url as the audio file name. ie,...
1
by: Sobin Thomas | last post by:
Hi,All... I found in one of the articles on the net that an audio file can be played in asp.net by setting the Hyperlink's Navigate Url as the audio file name. ie,...
1
by: Sobin Thomas | last post by:
Hi All, I want to play an audio file (wav)in my web page.I used the embed tag method.But it does'n work well in firefox.Is there any .NET class to play audio files?I already tried soundpalyer...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.