javascript cross browser element array like getElementsByTagName

Hi,

I am trying to provide a number of audio files for streamin playback, the files are .swf. Since there will be multiple <EMBED> tags my 1st problem was that all tracks could be played at the same time, and despite setting the autostart property to false all of the embedded sounds played on page load. I read that to prevent this to use the following javascript in body onload: document.elementid.rewind(). This indeed worked and nothing plays now till document.elementid.play() is called.

Now, since the embed tags are dynamically generated there could be any number of them, i needed a way to stop any playing track before starting another and i wrote these functions:

function stop_all()
      {
      //stop any other tracks
      var arrEmbedArray=document.getElementsByTagName("embed");
      for(var i=0;i<arrEmbedArray.length;i++)
            {
            arrEmbedArray[i].rewind()
            alert(i)
            }
      }

function start_track(strEmbedID)
      {
      stop_all()
      //start selected track
      var objCurrentEmbed=document.getElementById(strEmbedID);
      objCurrentEmbed.play()
      }

Really i wanted an "if" in the loopin stop_all() so the rewind is only called for the one playing track but i couldn't find a way so it is being called for each and every embed element, i'd like to change this but it works... Well, it's working in IE, but not in netscape, firefox, or opera. The alert in the loop was to test the loop was running and it isnt running in any other browser than IE.

I read that getElementsByTagName is supported as follows: IE v5 +, Firefox v1 + and opera v9 +. I think i may need to do things differently for these browsers, hope someone can help! thanks all.

s1desh0wAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DireOrbAntCommented:
Why don't you keep the current track and change like this:

var CurrentEmbedID = '';

function stop_track()
      {
       if (CurrentEmbedID != '')
        {
         document.getElementById(CurrentEmbedID).rewind();
         CurrentEmbedID = '';
        }
      }

function start_track(strEmbedID)
      {
      stop_track();
      //start selected track
      CurrentEmbedID = strEmbedID;
      document.getElementById(CurrentEmbedID).play()
      }
0
s1desh0wAuthor Commented:
yes, thanks, i did think of keeping the current track as a global var after making the post, i havnt tried it yet, i will let you know if that works, more importantly will this work cross browser because there is some problem in all browsers except ie that is preventing the code in my for loop from running (getElementsByTagName). In addition all tracks will play onload unless i call .rewind() for each one onload as well, thats what stop_all() is doing, so i should keep this function as is?

thanks for your help
0
DireOrbAntCommented:
I see now, are those Flash movies? getElementsByTagName works on IE and all others. The issue here is that IE will "hide" the embed tag from the DOM tree if it's inside an object tag (like flash movies should be if you use embed). Another option is to use getElementsByClassName, get the function here:
http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/

And the give all embeds AND objects a class="MyClips" or something...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
s1desh0wAuthor Commented:
i've used a workaround to get round this problem by using the following javescript to write the flash object to a <div> from an onclick event: It saves having to stop the tracks on load and on play.

function start_track(strEmbedSource)
      {
      objLayer=document.getElementById("obj_layer")
      objLayer.innerHTML='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" WIDTH=0 HEIGHT=0><PARAM NAME=movie VALUE="' + strEmbedSource + '" /><PARAM NAME=loop VALUE=false /><PARAM NAME=volume VALUE=100 /><PARAM NAME=quality VALUE=high /><EMBED src="' + strEmbedSource + '" loop=false volume=100 quality=high width=0 height=0 hidden=true type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>'
      }

the only problem i have remaining is that in the same way as setting <param name=autostart value=false> doesnt prevent these files from playing on load, setting <param name=loop value=false> doesnt prevent the track from looping either. as you can see from the code above i have included these values in both the param name and the embed tag, the files by the way are only audio but converted from mp3 to swf at a lower quality to save bandwidth on streaming, i used MP3 Stream trial version to do this, thanks again for ure help.
0
s1desh0wAuthor Commented:
p.s. i will award the points for your previous answer tho since i believe it would solve my original problem. cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.