I'm using Visual Studio 2017; and, I'm fairly new to coding. I'm trying to add a .wav audio file to a Clickable Button in my program. I first created a "Resource.resx" file and added the audio resource, with the changed 'properties' to "Embedded in .resx." Then added the method
playAudio();
...
private void playAudio()
{
SoundPlayer audio = new SoundPlayer(@"\Audio\Slots.wav");
}
in the button event of the code. The program runs fine as is; there's just no volume/sound. And yes, if I click on the .wav file in the Solution Explorer audio folder it plays just fine. Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Media;
namespace Casino
{
public partial class Default : System.Web.UI.Page
{
Random random = new Random();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string[] reels = new string[] { spinReel(), spinReel(), spinReel() };
displayImages(reels);
ViewState.Add("PlayersMoney", 100);
displayPlayersMoney();
}
}
protected void pullButton_Click(object sender, EventArgs e)
{
playAudio();
int bet = 0;
if (!int.TryParse(betTextBox.Text, out bet)) return;
int winnings = pullLever(bet);
displayResult(bet, winnings);
adjustPlayersMoney(bet, winnings);
displayPlayersMoney();
}
private void playAudio()
{
SoundPlayer audio = new SoundPlayer(@"\Audio\Slots.wav");
}
...
An option of the audio playing with PageLoad would be fine with me as well. Also, I've been told that .wav files only can be played. If so, why am I not able to use .mp3 files?
Thanks for any help/direction you can provide!