473,594 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4785
ab****@yahoo.co m 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 <objectelemen t shouldn't work:

var obj = document.create Element("object ");
obj.type = "audio/mpeg3";
obj.data = "http://my.audio.url";
document.body.a ppendChild(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.co m 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 <objectelemen t shouldn't work:

var obj = document.create Element("object ");
obj.type = "audio/mpeg3";
obj.data = "http://my.audio.url";
document.body.a ppendChild(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.co m wrote:
Jeremy wrote:
>ab****@yahoo.co m 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 <objectelemen t shouldn't work:

var obj = document.create Element("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
2681
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 have is ... <html> <head> <title>Dictionary: homeostasis</title> <link href="liveink.css" type="text/css" rel="stylesheet"/> </head>
2
5417
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 AUTOSTART="false"... In the good old days of Netscape 3 or so, just <A HREF="BWV659.mid">Musique</A> would open a small console in the active page itself, based on the plug-in selected by the user. Today, it opens
0
2339
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: homeostasis</title> <link href="liveink.css" type="text/css" rel="stylesheet"/> </head> <body>
0
1393
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 P ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>wH7cq4Ky8EGU49PmVxwSaA==</Id>
3
2343
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 embedded audio player. <embed src="slideshow/streetsound.mp3" width="75" height="25" autostart="true" loop="true">
3
2847
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 regards, sand...
13
2636
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 longer works. (I think it is considering the embed tag as an element in my form and I think that's causing the problem.) I think adding and specifying to only look at a div tag within the form would solve the problem but I'm not sure. Can someone...
0
1530
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. My need is to open a solution programmatically, select a Project within, and get a source resource file. Then, select a number of cultures and create culture specific resources with the content of the source resource assembly. I aquired upto...
7
4032
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. Before there are six characters entered in the CAPTCHA code field, the 'Send' button is supposed to be disabled. When there are at least six characters in the CAPTCHA code field, the script attempts to verify the CAPTCHA w/AJAX. If it verifies, it...
0
7946
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, 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...
0
7877
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,...
0
8374
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 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...
1
8009
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,...
0
6661
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, 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...
0
3867
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1482
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.