Current location: Hot Scripts Forums » General Web Coding » JavaScript » displaying image while loading external file


displaying image while loading external file

Reply
  #1 (permalink)  
Old 09-23-06, 04:27 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
displaying image while loading external file

hello all, back with a question:

i'm making a music player on my website, in javascript. Because i have a lot of music i don't want to load all the songs at the beginning, and then simply start playing them when hitting a button "Play".
i was thinking about using a function that will load the music file and then start playing the song. so far so good, i know how to do this. But while loading i would like to show an animated gif somzthing like this:
http://www.gifs.net/Animation11/Webd...ue_forward.gif

does anybody knows how to do so? i googled for "javascript load", and variants, but i couldn't find it. i checked www.w3schools.com as well

EDIT: if necessary i make this in flash, but i wanted to try javascript first

Thanx,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks


Last edited by UnrealEd; 09-23-06 at 04:37 AM.
Reply With Quote
  #2 (permalink)  
Old 09-23-06, 01:43 PM
ben.periton ben.periton is offline
Wannabe Coder
 
Join Date: Oct 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
Maybe you could use AJAX and call the file on demand, then while it is loading show the img, when it is done hide it.
__________________
Ben Periton
http://ben.periton.co.uk
Reply With Quote
  #3 (permalink)  
Old 09-23-06, 04:17 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Perhaps you could show the image as the background to a table, which would then be hidden behind the player when it loads. Or you could toggle the visibility of some layers to hide or show the image. Or even just toggle a couple of images via javascript, one would be the animated image, the other would be a blank or transparent image.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #4 (permalink)  
Old 09-24-06, 03:15 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
thx for the replies, but i allready know how i'm going to do it with the image.
this will be the code:
Code:
<img src="play.gif" onclick="javascript:_play(1)" id="play_1">
then i just switch the source of the image to loading.gif and then to pauze.gif when it's playing.

Quote:
Originally Posted by XTech
Maybe you could use AJAX and call the file on demand, then while it is loading show the img, when it is done hide it.
the only thing i don't know is how to make the while loop that checks whether the file is still loading:
Code:
function _play(id){
  // load the music file here....
  while(!file.loaded){  
    document.getElementById("play_"+id).src = "loading.gif";
  }
  document.getElementById("play_"+id).src = "pause.gif";
  document.getElementById("play_"+id).onclick = 'javascript:_pauze('+id+')';
}
this is how want it to be like. i just don't know how you check whether the file is completely loaded or not.

Thanx,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 09-24-06, 04:05 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
You could set the "loading" image on click, and then try
Code:
function _play(id){
  // load the music file here....
  file.onload = function()
  {
     document.getElementById("play_"+id).src = "pause.gif";
     document.getElementById("play_"+id).setAttribute('onclick', '_pauze('+id+');');
  }
}
Reply With Quote
  #6 (permalink)  
Old 09-24-06, 05:43 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
why didn't i think of that
there's only one problem: the onload doesn't work.
I can't get the file to be loaded. I searched the web, but the only thing i found were embeds with the source allready defined.
i wrote a function that simply changes the src of the embed to the specified file, but i won't load it, nor play it. here's the code:
Code:
function _play(){
	file = document.getElementById("embed");
	document.getElementById("img").src= "../Cyberbokken2.jpg";
	file.src = "garbage.wmv";
	if(file.onload()){
	        file.hidden = "false";
		document.getElementById("img").src = "../s0172578.jpg";
		file.play(false);
	}
}
i'm probably doing something wrong, but i can't find it. Sorry if this is something stupid
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Textfield, CSS stylesheet external loading Flash_Boi Flash & ActionScript 1 03-03-09 06:43 AM
Need Your HelP! Loading Multiple External Text into Multiple Dynamic Text Fields Flash_Boi Flash & ActionScript 2 03-30-06 03:27 PM
Loading external image on bcg aLf_bl Script Requests 4 12-10-05 11:06 PM
Image Upload, File Type Check, File Size Check CarBoffin PHP 3 04-13-04 02:26 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM


All times are GMT -5. The time now is 11:19 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.