0

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.

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by MichaelWClark
0

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>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.