This code was written by acoder serveral (139) days ago. So I decided to post it. -
-
function play() {
-
embed = document.createElement("embed");
-
embed.setAttribute("src", "soundfile.wav");
-
embed.setAttribute("hidden", true);
-
embed.setAttribute("autostart", true);
-
document.body.appendChild(embed);
-
}
-
-
^_^ Thanks, Death
3 18606 gits 5,390
Recognized Expert Moderator Expert
to make it a little bit more useful we should slightly adapt it to accept the file to play as a parameter, and strictly seen we should declare the variable embed :) -
-
function play(file) {
-
var embed = document.createElement("embed");
-
-
embed.setAttribute('src', file);
-
embed.setAttribute('hidden', true);
-
embed.setAttribute('autostart', true);
-
-
document.body.appendChild(embed);
-
}
-
so now we could simply call: - onclick="play('file.wav');"
on any element we want ...
kind regards
acoder 16,027
Recognized Expert Moderator MVP
I probably posted that from somewhere - no need to attribute it to me.
Besides the points made above, embed is actually non-standard, but sometimes required for backwards compatibility. The element to use now is object.
gits 5,390
Recognized Expert Moderator Expert
I probably posted that from somewhere - no need to attribute it to me.
Besides the points made above, embed is actually non-standard, but sometimes required for backwards compatibility. The element to use now is object.
so we could adapt it further :) -
-
function play(file, obj) {
-
if (typeof obj == 'undefined') {
-
obj = 'object';
-
}
-
-
var node = document.createElement(obj);
-
-
node.setAttribute('src', file);
-
node.setAttribute('hidden', true);
-
node.setAttribute('autostart', true);
-
-
document.body.appendChild(node);
-
}
-
now we could call: - onclick="play('file.wav');"
that creates the 'object' as default or: - onclick="play('file.wav', 'object');"
or even with 'embed' instead of 'object' in case we need to do that ;)
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Paul Moore |
last post by:
Does anyone know of a Python library which handles sound file formats
(MP3, Ogg, FLAC are the three I'm nost interested in). I'd like
something that can manipulate "metadata" - stuff like artist, title,
album tags. I'm not critically interested in format conversion, or
playing sound files - I can handle that with other applications.
I'm using Windows, and Python 2.3, if it matters (as it might for C
extensions).
I can manage with just...
|
by: Kim Forbes |
last post by:
Hello all,
I have simple function that I call from an alert box
alert(testScore);
It works fine. Unfortunately, I do not like the sound and Exclamation
point icon that appears. I'd like a nice message box like VBA message
box #64 to appear. I know hardly anything at all about VB or VBA.
But, I do know you can call a VB function from Javascript. How? Is it
|
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 seperate file in a specific directory,
but instead 'integrate' it in my application?
Thanks
peter
|
by: Serdge Kooleman |
last post by:
hi
i'm trying to play sounds in my windows app.
wav files are in the same folder as .exe
if i'm getting path by command:
ApplicationPath = Application.StartupPath;
and it is look like
|
by: Lam |
last post by:
how can I play sound file in a .aspx page written in C#?
I try to use the code like the following. But whenI call the play function
play("sound.wav", this.SND_ASYNC)
my computer give out "be" sound instead playing the file
(same code works fine in a windows application written in c# , that mean
there is nothing wrong with my sound card.)
thanks
----------------------------------------------------------------------------...
| |
by: Xero |
last post by:
Is there a simpler way to play from a sound file than this one
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbcode/html/vbtskcodeexampleplayingsound.asp
Thanks.
--
Xero
http://www.chezjeff.net
My personal web portal
|
by: Benzerari |
last post by:
Hi All;
Please, if any one knows the visual basic code, to be added to a Stop button in order to stop playing some sound of (*.Wav) type. I have achieved to find the code for start playing sound or music which is:
OLE.DoVerb (vbOLEPrimary)
But the one to stop or interupt the sound I could not find it.
Please let know
|
by: Jake Barnes |
last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching
for "how to play a sound with Javascript". I'm somewhat suprised that
the majority of entries are from the 1990s, and there are almost no
posts from the last 3 years:
http://groups.google.com/group/comp.lang.javascript/search?group=comp.lang.javascript&q=how+to+play+a+sound+with+Javascript&qt_g=Search+this+group
Even after sorting by date, there don't appear any...
|
by: Sheena777 |
last post by:
I want to Play a specific sound file in my code when a certain event happens, but i don't know how. I can play the system sounds in my program and I know how to start the media player to play an mp3 but I want to be able to play the sound file without an external player. Is there any other way of playing a sound file in vb.net code when an event is fired?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |