AutoPlay Audio On Page Load using Code Behind in C# and VB.Net

Last Reply 11 months ago By pandeyism

Posted 11 months ago

I am using html 5 audio player i want to assign the src to it on page load and click on play button from page behind but its not working pls advice.

 <audio id="buzz" runat="server"   type="audio/mp3"/>


buzz.Src = "../images/filling-your-inbox.mp3";
buzz.Style.Add("autoPlay", "autoPlay");


Posted 11 months ago Modified on 11 months ago

Hi nauna,

Refer below sample.


<audio controls id="buzz" runat="server" type="audio/mp3" />



protected void Page_Load(object sender, EventArgs e)
    buzz.Attributes.Add("autoplay", "autoplay");
    buzz.Attributes["src"] = "Test.mp3";


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handle Me.Load
    buzz.Attributes.Add("autoplay", "autoplay")
    buzz.Attributes("src") = "Test.mp3"
End Sub