|
-
Aug 31st, 2005, 08:21 PM
#1
Thread Starter
Frenzied Member
play mp3 file
How do I play mp3 file in .Net? I have read that using DirectX/openGL will do the trick. So I hope JR will help me through this.
Btw Im using 1.0 framework.
Last edited by mar_zim; Aug 31st, 2005 at 10:17 PM.
-
Aug 31st, 2005, 10:00 PM
#2
Re: play mp3 file
I'm sure you can use DirectX, but you can also use MCI via Windows API, or reference the Windows Media Player COM library and use a WindowsMediaPlayerClass object, which is like the ActiveX control but without the UI.
-
Aug 31st, 2005, 10:08 PM
#3
Thread Starter
Frenzied Member
Re: play mp3 file
got any good article/tutorial about that?
-
Aug 31st, 2005, 10:33 PM
#4
Re: play mp3 file
Only the MSDN topics I'm afraid as I haven't really used either myself.
MCI
WMP
If you're interested in MCI then you could check out some of wldrumstcs recent posts, as he's building a media player using purely MCI.
-
Sep 2nd, 2005, 04:58 PM
#5
Re: play mp3 file
top of your code window ...
VB Code:
[COLOR=Green]/// add these 2 references ... [/COLOR]
[COLOR=Blue]using[/COLOR] System.Runtime.InteropServices;
[COLOR=Blue]using[/COLOR] System.Text;
to use, a simple bit of code that allows you to open / play / stop an mp3 i put together ...
VB Code:
[DllImport("winmm.dll", EntryPoint="mciSendStringA")]
[COLOR=Blue]private static extern int [/COLOR] mciSendString ([COLOR=Blue]string[/COLOR] lpstrCommand, [COLOR=Blue]string[/COLOR] lpstrReturnString, [COLOR=Blue]int[/COLOR] uReturnLength, [COLOR=Blue]int[/COLOR] hwndCallback);
[DllImport("kernel32.dll", EntryPoint="GetShortPathNameA")]
[COLOR=Blue]private static extern int[/COLOR] GetShortPathName ([COLOR=Blue]string[/COLOR] lpszLongPath, StringBuilder lpszShortPath, [COLOR=Blue]int[/COLOR] cchBuffer);
[COLOR=Blue]private string[/COLOR] Alias = "MP3";
[COLOR=Blue]private void[/COLOR] btnplay_Click([COLOR=Blue]object[/COLOR] sender, System.EventArgs e)
{
OpenFileDialog od = [COLOR=Blue]new[/COLOR] OpenFileDialog();
od.Filter = "MP3 Audio(*.mp3)|*.mp3";
od.RestoreDirectory = [COLOR=Blue]false[/COLOR];
[COLOR=Blue]if[/COLOR](od.ShowDialog() == DialogResult.OK)
{
[COLOR=Green] /// we need to get the short path name of our file
/// eg: E:\Iron Maiden\(1980) Iron Maiden\04 - Phantom Of The Opera.mp3
/// becomes E:\IRONMA~1\(1980)~1\04-PHA~1.MP3
/// to do this we use the GetShortPathName API
/// and the System.Text.StringBuilder class to receive the ShortPathName. [/COLOR]
StringBuilder sbuild = [COLOR=Blue]new[/COLOR] StringBuilder(256);
GetShortPathName(od.FileName , sbuild , sbuild.Capacity);
Play(sbuild.ToString());
}
}
[COLOR=Blue]private void[/COLOR] Play([COLOR=Blue]string[/COLOR] Mp3)
{
[COLOR=Green]/// open the mp3 file ( mp3 uses the Type MPEGVideo ) [/COLOR]
[COLOR=Blue]int[/COLOR] x = mciSendString("open " + Mp3 + " Type MPEGVideo Alias " + Alias , [COLOR=Blue]null[/COLOR] , 0 , 0);
[COLOR=Green]/// play the mp3 [/COLOR]
x = mciSendString("play " + Alias , [COLOR=Blue]null[/COLOR] , 0 , 0);
}
[COLOR=Blue]private void[/COLOR] Stop()
{
[COLOR=Blue]int[/COLOR] x = mciSendString("stop " + Alias , [COLOR=Blue]null[/COLOR] , 0 , 0);
}
[COLOR=Blue]private void[/COLOR] btnstop_Click([COLOR=Blue]object[/COLOR] sender, System.EventArgs e)
{
Stop();
}
hope it helps
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 4th, 2005, 08:20 PM
#6
Thread Starter
Frenzied Member
Re: play mp3 file
Thanks dynamic_sysop if I have some extra time I'll try that one.
Nice to see you back.
-
Sep 4th, 2005, 09:59 PM
#7
Thread Starter
Frenzied Member
Re: play mp3 file
I already tested it. Yeah it works but in only one file. 
Actually I add all the list of mp3 in a listbox and select a file then play it and it works fine but when I choose another mp3 file in the listbox then the problem occur, it wont work.
-
Sep 6th, 2005, 04:34 PM
#8
Re: play mp3 file
sorry i haven't been able to post a message back, my wife was rushed in to hospital yesterday, she has severe pneumonia ( which isn't good considering she's also 33 weeks pregnant )
if i get an opertunaty i'll do a Directsound example sometime, but it'll be a while.
regards, den ( aka dynamic )
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 6th, 2005, 08:06 PM
#9
Thread Starter
Frenzied Member
Re: play mp3 file
 Originally Posted by dynamic_sysop
sorry i haven't been able to post a message back, my wife was rushed in to hospital yesterday, she has severe pneumonia ( which isn't good considering she's also 33 weeks pregnant )
if i get an opertunaty i'll do a Directsound example sometime, but it'll be a while.
regards, den ( aka dynamic )
I'm very sorry to hear that. I hope your wife will get well considering she's bearing your 3rd child and it's a boy(in your sig).
Don't worry mate I'll just wait till you reply.
-
Sep 7th, 2005, 03:29 AM
#10
-
Sep 7th, 2005, 05:20 AM
#11
PowerPoster
Re: play mp3 file
using DirectX audio is easy too
just add a reference to DirectX.AudioVideoPlayback;
then:
Code:
Audio myAudioFile = new Audio("Pathtoaudiofile.xxx");
myAudioFile.Play();
it maybe .Start() instead of Play but i cant remember
pretty much thats it
-
Sep 10th, 2005, 12:49 AM
#12
-
Sep 10th, 2005, 12:52 AM
#13
PowerPoster
Re: play mp3 file
right 
but directx is built into Windows, since Windows 98SE (I think) but defo in 2000/2003/Longhorn/Windows 98SE/ME
-
Sep 10th, 2005, 01:09 AM
#14
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|