Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Using Ajax to embed audio file in HTML?

Reply
Thread Tools

Using Ajax to embed audio file in HTML?

 
 
abrtlt@yahoo.com
Guest
Posts: n/a
 
      10-11-2006
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

 
Reply With Quote
 
 
 
 
Jeremy
Guest
Posts: n/a
 
      10-11-2006
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 <object> element 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
 
Reply With Quote
 
 
 
 
abrtlt@yahoo.com
Guest
Posts: n/a
 
      10-11-2006

Jeremy wrote:
> 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 <object> element 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 <EMBED> but starts a
WMP window if I use <OBJECT>.
Andrew

 
Reply With Quote
 
Jeremy
Guest
Posts: n/a
 
      10-12-2006
wrote:
> Jeremy wrote:
>> 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 <object> element 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 <EMBED> but starts a
> WMP window if I use <OBJECT>.
> Andrew
>


You have to be careful with IE and <object> to get it to work properly.
Some finesse usually does the trick (google Flash Satay for an article
on getting <object> to work well). In any case, you should avoid
<embed> as it's not a valid element.

Jeremy
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to embed audio <OBJECT/>s conditional on browser capabilities ewan.dunbar@utoronto.ca HTML 2 03-19-2008 07:29 PM
Embed ".html" file into ".aspx" file yukijocelyn ASP .Net 0 08-06-2007 08:41 AM
Embed image in html with ajax Manuel Javascript 6 07-02-2007 06:57 PM
how mix multi-audio file to a audio file? aeonsun Java 2 03-11-2007 06:07 AM
AJAX IDE and AJAX TOOL--The Release of JoyiStar AJAX WebShop 3 Beta minnie Java 1 12-13-2006 06:29 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57