Hello,
I'm a beginner in C# and I want to read a sound file. I found this code in the net and I tried to correct it:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
using System.Runtime.InteropServices;
using System.Media;
namespace alarmee
{
public partial class Form1 : Form
{
public Audio Lecteur;
public bool lecture = false;
public Form1()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint = "PlaySound", SetLastError = true, CharSet = CharSet.Unicode, ThrowOnUnmappableChar = true)]
private static extern bool PlaySound(string szSound, System.IntPtr hMod, PlaySoundFlags flags);
[System.Flags]
public enum PlaySoundFlags : int
{
SND_SYNC = 0x0000,
SND_ASYNC = 0x0001,
SND_NODEFAULT = 0x0002,
SND_LOOP = 0x0008,
SND_NOSTOP = 0x0010,
SND_NOWAIT = 0x00002000,
SND_FILENAME = 0x00020000,
SND_RESOURCE = 0x00040004
}
private void button4_Click(object sender, EventArgs e)
{
}
System.Media.SoundPlayer sp = new SoundPlayer();
private void button1_Click(object sender, EventArgs e)
{
sp.SoundLocation = "C:\\Sample\\alarme.wav";
sp.LoadCompleted += new AsyncCompletedEventHandler(sp_LoadCompleted);
sp.LoadAsync();
}
private void sp_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
sp.PlayLooping();
}
}
}
Now I want to read the sound file without specifying its exact location because it's not practical to demand to a person who wants to use my application to have the same file.wav in the same location.
Hope you can understand what I wrote. Thank you in advance. Good day.