473,413 Members | 1,727 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,413 software developers and data experts.

Using Ajax to embed audio file in HTML?

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 obtained from a PHP script (accessing
a MySQL database) that could be called using XMLHttpRequest and
JavaScript would write in a "div" tag an "embed and play" HTML tag
containing the audio file name.
I am not sure this would work, as the embed tag is HTML and will not be
executed as the page has already been loaded. In any case, unless I am
mistaken, JavaScript in the web page can handle only a text or XML
response, and thus I can get the audio file name, but not the file
itself. I can't pre-embed all audio files in the page because there are
too many (that is why I use MySQL to index them).
Is there any way to get round this?
Thanks!

Andrew

Oct 11 '06 #1
3 4753
ab****@yahoo.com wrote:
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 obtained from a PHP script (accessing
a MySQL database) that could be called using XMLHttpRequest and
JavaScript would write in a "div" tag an "embed and play" HTML tag
containing the audio file name.
I am not sure this would work, as the embed tag is HTML and will not be
executed as the page has already been loaded. In any case, unless I am
mistaken, JavaScript in the web page can handle only a text or XML
response, and thus I can get the audio file name, but not the file
itself. I can't pre-embed all audio files in the page because there are
too many (that is why I use MySQL to index them).
Is there any way to get round this?
Thanks!

Andrew
According to specifications, there is no reason why a dynamically
created <objectelement shouldn't work:

var obj = document.createElement("object");
obj.type = "audio/mpeg3";
obj.data = "http://my.audio.url";
document.body.appendChild(obj);

In practice, I've no idea how well that would work. It seems to work
flawlessly in Firefox, although no controls are presented (or if they
are I can't see them).

Jeremy
Oct 11 '06 #2

Jeremy wrote:
ab****@yahoo.com wrote:
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 obtained from a PHP script (accessing
a MySQL database) that could be called using XMLHttpRequest and
JavaScript would write in a "div" tag an "embed and play" HTML tag
containing the audio file name.
I am not sure this would work, as the embed tag is HTML and will not be
executed as the page has already been loaded. In any case, unless I am
mistaken, JavaScript in the web page can handle only a text or XML
response, and thus I can get the audio file name, but not the file
itself. I can't pre-embed all audio files in the page because there are
too many (that is why I use MySQL to index them).
Is there any way to get round this?
Thanks!

Andrew

According to specifications, there is no reason why a dynamically
created <objectelement shouldn't work:

var obj = document.createElement("object");
obj.type = "audio/mpeg3";
obj.data = "http://my.audio.url";
document.body.appendChild(obj);

In practice, I've no idea how well that would work. It seems to work
flawlessly in Firefox, although no controls are presented (or if they
are I can't see them).

Jeremy

Thanks. Yes, you must be right. I have a non-Ajax PHP /Javascript page
that works fine by reloading and shows (with IE) neither controls nor
separate mp3 player (I don't want them) if I use <EMBEDbut starts a
WMP window if I use <OBJECT>.
Andrew

Oct 11 '06 #3
ab****@yahoo.com wrote:
Jeremy wrote:
>ab****@yahoo.com wrote:
>>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 obtained from a PHP script (accessing
a MySQL database) that could be called using XMLHttpRequest and
JavaScript would write in a "div" tag an "embed and play" HTML tag
containing the audio file name.
I am not sure this would work, as the embed tag is HTML and will not be
executed as the page has already been loaded. In any case, unless I am
mistaken, JavaScript in the web page can handle only a text or XML
response, and thus I can get the audio file name, but not the file
itself. I can't pre-embed all audio files in the page because there are
too many (that is why I use MySQL to index them).
Is there any way to get round this?
Thanks!

Andrew
According to specifications, there is no reason why a dynamically
created <objectelement shouldn't work:

var obj = document.createElement("object");
obj.type = "audio/mpeg3";
obj.data = "http://my.audio.url";
document.body.appendChild(obj);

In practice, I've no idea how well that would work. It seems to work
flawlessly in Firefox, although no controls are presented (or if they
are I can't see them).

Jeremy


Thanks. Yes, you must be right. I have a non-Ajax PHP /Javascript page
that works fine by reloading and shows (with IE) neither controls nor
separate mp3 player (I don't want them) if I use <EMBEDbut starts a
WMP window if I use <OBJECT>.
Andrew
You have to be careful with IE and <objectto get it to work properly.
Some finesse usually does the trick (google Flash Satay for an article
on getting <objectto work well). In any case, you should avoid
<embedas it's not a valid element.

Jeremy
Oct 12 '06 #4

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

Similar topics

1
by: laredotornado | last post by:
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...
2
by: François de Dardel | last post by:
Please don't scream that EMBED is evil ! What I am doing is <EMBED SRC="BWV659.mid" AUTOSTART="false" LOOP="TRUE" CONTROLS="SMALLCONSOLE" WIDTH="50" HEIGHT="15" TITLE="BWV 659"> Note the...
0
by: laredotornado | last post by:
Hello, I want to play an audio file by clicking on an audio icon and not having the page switch out underneath. Right now the code I have is ... <html> <head> <title>Dictionary:...
0
by: Jin P via .NET 247 | last post by:
how you guys embed an audio file (let say wav format) in a resx file? I can embed images but somehow when I try to embed audios, it said out of memory. -------------------------------- From: Jin...
3
by: Chris Tomlinson | last post by:
Hi all, I hope someone is able to help me out with a small problem with this page: http://www.superhighstreet.com/George-Street-Richmond/index.shtml I have a small iframe (mid-right) with an...
3
by: sandeepk84 | last post by:
hi all... can anyone tell me how can i embed an audio player in my web page in html or jsp...which will help users with almost all the types of browsers, listen to it...plz help... thanx and...
13
by: windsorben | last post by:
I have some javascript that checks whether or not an answer is correct. It was working fine when the question was asked with text but now that I'm asking the question with audio, the javascript no...
0
by: VigneshS | last post by:
Hi, I am a newbie to Globalization and Localisation Concepts. I tried almost all the methods of the Globalization concepts. But i cannot be able to embed a text file within a Resource. ...
7
by: mike57 | last post by:
The minimal AJAX script below works in Firefox, but not in IE, Opera, or Chrome. I could use some suggestions or referrals to resources that will help me get the script working in other browsers. ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
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...
0
agi2029
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,...
0
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...

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.