All the tutorials at the
irrKlang page are using a console as example application type, because I thought it would be more simple to understand, but a lot of people asked me how to use irrKlang together with Windows.Forms. So here is a small example code, showing how to play back any sound file (mp3, ogg, wav, whatever) using irrKlang, in a small Windows.Forms application:
You only need to
download irrKlang and add the irrKlang.NET.DLL file as reference to your project.
// Minimal Windows.Forms program in CSharp// to play back an .ogg, mp3, .mod, .wav etc file:using System;using System.Windows.Forms;namespace PlayerApplication{ public class PlayerWindow : Form { irrKlang.ISoundEngine soundEngine = new irrKlang.ISoundEngine(); irrKlang.ISound currentlyPlayingSound; [STAThread] static void Main() { Application.Run(new PlayerWindow()); } public PlayerWindow() { // setup window Button playButton = new Button(); Button stopButton = new Button(); playButton.Location = new System.Drawing.Point(48, 78); playButton.Text = "Play"; playButton.Click += new System.EventHandler(PlayButton_Click); stopButton.Location = new System.Drawing.Point(173, 78); stopButton.Text = "Stop"; stopButton.Click += new System.EventHandler(StopButton_Click); Controls.Add(stopButton); Controls.Add(playButton); } private void PlayButton_Click(object sender, EventArgs e) { // replace the filename with the file you want to play. // copy the ikpmp3.dll to your bin\Debug (or working) path if you want // to play back mp3 files currentlyPlayingSound = soundEngine.Play2D(@"C:\music\someFile.ogg"); } private void StopButton_Click(object sender, EventArgs e) { if (currentlyPlayingSound != null) { currentlyPlayingSound.Stop(); currentlyPlayingSound = null; } } }}
I really don't understand what the big deal is, it should not be that difficult. :)
Shouldn't you be calling something like
currentlyPlayingSound.Dispose()
when you play a new sound or does the engine take care of everything? How do you manage resources in this case?