How to autoplay the link in Anchor tag

Hello all,

    I have to play a audio file on my web page automatically. I am using Yahoo Media Player.

Right now I am playing the audio like this....

    <script type="text/javascript" src="http://mediaplayer.yahoo.com/js"></script>

<td>  <a  id= "songlink" runat = "server"  visible ="false" >Play Advertisement</a>
                            </td>

I am giving the href in code behind( based on the user location)

Code Behind:

                        songlink.HRef = "Media/song1.mp3"
                        songlink.Visible = True

With this method, I have to click on the link, to play the song..

But, I would like to play the song automatically( without any click) . Is it possible to do so from code behind?

Appreciate the help

Thanks
shahjagatAsked:
Who is Participating?
 
shahjagatAuthor Commented:
Hello All,

   I ended up using this script. Works perfect..

<script>
/** On Yahoo Media API Ready **/
var yesReady = false;
YAHOO.MediaPlayer.onAPIReady.subscribe(function(){
  yesReady = true;
});

function play(){

  //Capture the URL of the song
  var url = document.getElementById('<%=hidurl.ClientID %>').value;
  //Put it in Href of Song Link
 
  document.getElementById("<%=songlink.ClientID %>").href = url;

  //After that Play the Song using YMP
  if(yesReady){
 
    YAHOO.MediaPlayer.addTracks(document.getElementById('songdiv'), 0, true);
    YAHOO.MediaPlayer.play();
  }
}
</script>

<td align = "center"  >
                                      <div id='songdiv'>
                            <a  id= "songlink" runat = "server"  style="font-size:large ; color: Blue; background-color: Silver; border-color: Maroon"   >Click here to Play Advertisement</a>
                            </div>
                            </td>
                            <td>
                               <asp:HiddenField ID="hidurl" runat="server"  Value = ""></asp:HiddenField> </td>

Thank you all.
0
 
shahjagatAuthor Commented:
Hello CodeCruiser,

  The song comes from my side, I am just using the yahoo media player to play the song.

I am changing the Href of the anchor tag from code behind.
Song1.mp3 comes from the Media folder of my project.

Thanks
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Gurvinder Pal SinghCommented:
check this solution
http://www.entheosweb.com/website_design/play_sound.asp

just check if you can change the source of embed object from code behind
0
 
shahjagatAuthor Commented:
Hello gurvinder,

  This web app will be used in the tablets, so there will be now mouseover and I would like to have the audio played without any click . Is it possible?

Thanks
0
 
shahjagatAuthor Commented:
autoplay using javascript worked fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.