• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

Embed Src question

Why i can't change the src of the embed player to play another song...
How to do when i select a value on the dropdown menu to change the src of the embed player ?


   Music Player :
   <br />
    <select name="musiclist" onchange="javascript:MusicChange(this);">
     <optgroup label="WMA">
      <option value="WMA-1"> Unknown </option>
     </optgroup>
     <optgroup label="MP3">
      <option value="MP3-1"> The Reason </option>
     </optgroup>
     <optgroup label="MIDI">
      <option value="Midi-1.mid" selected> Midi-1 </option>
      <option value="Midi-2.mid"> Midi-2 </option>
      <option value="Midi-3.mid"> Midi-3 </option>
     </optgroup>
    </select>
   <br />
    <embed name="musicplayer" src="gallery/audio/midi-1.mid" width="120" height="45" hidden="false" autostart="true" loop="true">


<script language="javascript">

function MusicChange(list)
  {
   document.musicplayer.src = "gallery/audio/" + list.value;
  }

</script>
0
idiots
Asked:
idiots
3 Solutions
 
BatalfCommented:
I have searched the net for a solution to your problem, but it's not easy to find. Someone else could probably provide you with a better solution than mine.

This is just a workaround:



<body>
<script language="javascript">

function MusicChange(list){
    document.getElementById('myDiv').removeChild(document.getElementById('myDiv').childNodes[0]);
    var obj = document.createElement('EMBED');
    obj.src = list.value;
    obj.width = 120;
    obj.height = 45;
    obj.hidden = false;
    obj.autostart  = '1';
    obj.loop = 'false';
    document.getElementById('myDiv').appendChild(obj);  
}
</script>
<br />
    <select name="musiclist" onchange="javascript:MusicChange(this);">
     <optgroup label="WMA">
      <option value="WMA-1"> Unknown </option>
     </optgroup>
     <optgroup label="MP3">
      <option value="MP3-1"> The Reason </option>
     </optgroup>
     <optgroup label="MIDI">
      <option value="Midi-1.mid" selected> Midi-1 </option>
      <option value="Midi-2.mid"> Midi-2 </option>
      <option value="Midi-3.mid"> Midi-3 </option>
     </optgroup>
    </select>
   <br />
   <div id="myDiv">
    <embed id="musicplayer" src="gallery/audio/midi-1.mid" width="120" height="45" hidden="false" autostart="true" loop="true">
   </div>

</body>
</html>

0
 
xavieshCommented:
Please check this out ....

http://developer.irt.org/script/sound.htm
0
 
craigwardmanCommented:
the img tag can now display sound/video clips by setting the dynsrc attribute..

<img dynsrc="mid1.mid" id="musicplayer">

then the script can simply be:


document.getElementById('musicplayer').dynsrc=list.value;


I havent tested that, so you may need to change it slightly, but that should point you in the right direction..
0
 
idiotsAuthor Commented:
It can't help ...
and I don't know whose post is better...
so i'll split points ...

thanks...
0
 
idiotsAuthor Commented:
and I can't give A:Excellent for this question...
so i gave a B instead...
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now