jeudi 2 avril 2015

Play sound at buton press

I want a sound player to play as long as a button is pressed.


Here is what I've done so far :



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test
{
public partial class Form1 : Form
{
private SoundPlayer soundPlayer;

private void FormMain_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == 'n')
{
SoundPlayer s = new SoundPlayer(@"C:\Users\darude_rig\Desktop\dayz sounboard\media\sounds\AKM.wav");
s.PlayLooping();
}
}
}
}


Where is the problem and how can I fix it?


Aucun commentaire:

Enregistrer un commentaire