"Hai Ly Hoang" <No*****@Mail.c om> ha scritto nel messaggio
news:Of******** ******@TK2MSFTN GP10.phx.gbl...
I want to play a piece of music in .NET application
How to do that ?
You can try with the managed DirectX or with the OpenAL porting Tao.OpenAL
too.
Here is a piece of code I use for playing mp3 files with DirectSound. Hope
it can be useful.
Just look at the methods Music_Load(stri ng filename) and Music_Play().
using System;
using System.Windows. Forms;
using Microsoft.Direc tX;
using Microsoft.Direc tX.AudioVideoPl ayback;
[...]
private Audio ourAudio = null;
{...]
private int Music_Load(stri ng filename)
{
try
{
ourAudio = new Audio(filename) ;
ourAudio.Ending += new System.EventHan dler(this.Music _ClipEnded); //CALLED
AT THE END
}
catch
{
MessageBox.Show ("Error", "Invalid/corrupted file?.", MessageBoxButto ns.OK,
MessageBoxIcon. Information);
return -1;
}
return 0;
}
private int Music_Play()
{
try
{
ourAudio.Play() ;
return 0;
}
catch
{
MessageBox.Show ("Error", "Music_Play () failed.", MessageBoxButto ns.OK,
MessageBoxIcon. Information);
return -1;
}
}
private void Music_ClipEnded (object sender, System.EventArg s e)
{
if (ourAudio != null)
{
ourAudio.Stop() ;
ourAudio.Play() ; //LOOP PLAY
}
}