Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to autoplay the link in Anchor tag

Posted on 2011-10-20
6
Medium Priority
?
549 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:shahjagat
  • 4
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37003306
0
 

Author Comment

by:shahjagat
ID: 37003357
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
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 37004600
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:shahjagat
ID: 37006540
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
 

Accepted Solution

by:
shahjagat earned 0 total points
ID: 37009183
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
 

Author Closing Comment

by:shahjagat
ID: 37136782
autoplay using javascript worked fine.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question