I have uploaded audio files (saved them) into the SQL Server 2005 database.

I need to prepare a "play sound" button to allow users to click it and listen to the sound.

I have the following code to retrieve the audio file from the database.

  protected void playsound_btn_Click(object sender, ImageClickEventArgs e)
  {
    Label Sound_nameLabel = (Label)QuestionsFormView.FindControl("Sound_nameLabel");
    string soundName = Sound_nameLabel.Text;

    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["preschoolkidsConnectionString"].ConnectionString);
    connection.Open();

    SqlCommand dCmd = new SqlCommand("SelectAudioBySoundName", connection);
    dCmd.CommandType = CommandType.StoredProcedure;

    try
    {
      SqlParameter param = new SqlParameter("@Sound_name", SqlDbType.VarChar, 50);
      param.Value = soundName;
      dCmd.Parameters.Add(param);
      DataTable dt = new DataTable();
      SqlDataReader dr = dCmd.ExecuteReader();
      dt.Load(dr);

      byte[] stream = (byte[])dt.Rows[0][0];
    }

    catch
    {
      throw;
    }

    finally
    {
      dCmd.Dispose();
      connection.Close();
      connection.Dispose();
    }
  }

But I could not find a way to to code it so that can play it on user click.

Please help me...thank you.

p/s: im doing web application.

Javascript is easier for this i think.


<script language="javascript" type="text/javascript">
function playSound(soundfile) {
document.getElementById("dummy").innerHTML=
"<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
</script>


<a href="#" onclick="playSound('URL to soundfile');">Click here to hear a sound</a>

<p onmouseover="playSound('URL to soundfile');">Mouse over this text to hear a sound</p>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.