By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,969 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,969 IT Pros & Developers. It's quick & easy.

dynamic audio loading

P: 13
hi,
I'm trying to load audio files dynamicly but i got some errors.

my code :
Expand|Select|Wrap|Line Numbers
  1. File.prototype.OpenAudioFile = function(dPath)
  2. {
  3.     aSound= document.createElement("embed");
  4.     aSound.src = dPath;
  5.     aSound.name = "ses";
  6.     this.data = aSound;
  7.     aSound.onload = this.FileDownloaded();
  8. }
it doesnt work and i tried :
Expand|Select|Wrap|Line Numbers
  1. document.write("<embed src=" + dPath + " name=" + dPath + " autostart=false onload=this.FileDownloaded()></embed>");
and
Expand|Select|Wrap|Line Numbers
  1. document.write("<bgsound src=" + dPath + " name=" + dPath + " autostart=false onload=this.FileDownloaded()></embed>");
first code didnt work and other two work but when they load i can see just single color, no image, no text nth else. When i use embed tag staticly it works great.waiting for answers...
Aug 24 '09 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
in Firefox you may run into problems because of the built-in File object (which has nothing to do with <embed>)

other than that:
- line 3: the created object is not attached to the document tree anywhere
- line 7: what does this method do?
- how do you know that <embed> and <bgsound> are members of the File object/interface?

note: you should quote all HTML attribute values (this becomes necessary in XHTML)
Aug 24 '09 #2

P: 13
as i see in some file loader code "onload" function was used as a callback to check if element loading is completed. after geting message from onload i do something else and i call
document.body.appendChild(this.audio);
in a different class. i can see all properties of aSound and this.data from this.audio.
and i dont understand with file object but i just tested. i wasnt sure which one will work. i had some base knowledge and i just tested :)
Aug 24 '09 #3

P: 13
Expand|Select|Wrap|Line Numbers
  1. File.prototype.OpenAudioFile = function(dPath)
  2. {
  3.     var rem = document.createElement("div")
  4.     rem.name = "divv";
  5.     rem.id = "divId";
  6.  
  7.     rem.innerHTML = '<embed src="' + dPath + '" autostart="false" name="' + dPath + '"></embed>';
  8.  
  9.     document.body.appendChild(rem);
  10. }
  11.  
my sound problem is solved using the way above but when i attach div object to document sound plays automaticly.is there any solution for it?

by the way, im not working on internet browsers, it's a part of a framework for tv. it supports js 1.2.
Aug 26 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.