I am trying to play a wav file form a projects resources.
I found this example: Click Here
I imported two wav files per instructions named "Button.wav" and "Stop.wav".
I commented out this line Stream soundStream;
because it did not seem to belong.
When I run the code the sound files do not play, but I do get the "Windows Ding" sound.
This is issue is not critical, just a proff of principle for me at this point.
fyi... I tried it with and without Stream soundStream;
before posting.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
using System.Resources;
using System.Media;
using System.Diagnostics;
namespace GC_RunTimeCalculater
{
public partial class Form1 : Form
{
decimal totalRunTime = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
Assembly assembly;
// Stream soundStream;
SoundPlayer sp;
assembly = Assembly.GetExecutingAssembly();
sp = new SoundPlayer(assembly.GetManifestResourceStream("Button.wav"));
sp.Play();
}
if (secondTemp.Value < startTemp.Value)
{
Assembly assembly;
//Stream soundStream;
SoundPlayer sp;
assembly = Assembly.GetExecutingAssembly();
sp = new SoundPlayer(assembly.GetManifestResourceStream("Stop.wav"));
sp.Play();
MessageBox.Show("2nd Temp is less than Start Temp.", "Wait!!");
}
if (secondTemp.Value > finalTemp.Value)
{
Assembly assembly;
//Stream soundStream;
SoundPlayer sp;
assembly = Assembly.GetExecutingAssembly();
sp = new SoundPlayer(assembly.GetManifestResourceStream("Stop.wav"));
sp.Play();
MessageBox.Show("Final Temp is less than 2n Temp.", "Wait!!");
}
#region old div by zero
//code not need, set the min ramp value to 1, dah!!
//if ((ramp1.Value == 0) || (ramp2.Value == 0))
//{
// MessageBox.Show("Ramp cannot be 0!!");
// labelTotalRunTime.Text = "";
// return;
//}
#endregion
totalRunTime = (secondTemp.Value - startTemp.Value) / ramp1.Value + initialHold.Value +
(finalTemp.Value - secondTemp.Value) / ramp2.Value + finalHold.Value;
//totalRunTime = secondTemp.Value - startTemp.Value;
//totalRunTime = totalRunTime / ramp1.Value + initialHold.Value;
//totalRunTime = totalRunTime + finalTemp.Value - secondTemp.Value / ramp2.Value + finalHold.Value;
labelTotalRunTime.Text = totalRunTime.ToString();
}
private void finalTemp_ValueChanged(object sender, EventArgs e)
{
}
private void secondTemp_ValueChanged(object sender, EventArgs e)
{
finalTemp.Value = secondTemp.Value;
}
}
}