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

Last Reply 2 months ago By pandeyism

Posted 2 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"/>

 Code

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

 

Posted 2 months ago Modified on 2 months ago

Hi nauna,

Refer below sample.

HTML

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

Code

C#

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

VB.Net

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