[RESOLVED] Play MP3 File in Console Application
Hello, I was wondering if it is possible to play an MP3 file in a console application without using the Windows Media Player control (which is a bit annoying to use and would be more annoying on a console application) or DirectSound (which is not available in VS 2010)?
Thanks in advance!
Re: Play MP3 File in Console Application
try this:
vb Code:
Module Module1
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As _
Integer, ByVal hwndCallback As Integer) As Integer
Sub Main()
Dim _fileToPlay As String = Chr(34) + ("filename.mp3") + Chr(34)
Console.WriteLine("play mp3? [y/n]")
If Console.ReadLine.ToUpper = "Y" Then
mciSendString("open " & _fileToPlay & " alias myDevice", Nothing, 0, 0)
mciSendString("play myDevice", Nothing, 0, 0)
Console.ReadLine()
End If
End Sub
End Module
Re: Play MP3 File in Console Application
I think .paul. code will cover you fine but if you want something more complicated ( i had a crazy moment and i made this :p )you can see my application here:
http://www.vbforums.com/showthread.php?p=3948319
Re: Play MP3 File in Console Application
Thank you .paul., it works perfectly! If it's at all possible, how do you make it synchronous? (If it isn't, never mind!)
Re: [RESOLVED] Play MP3 File in Console Application
Okay, I just found out a way to do it, but it involves using window handles which are not that great in a console application. Instead, I run mciSendString("close mySound", Nothing, 0, 0) when the user presses Enter. Resolved x 2
Re: [RESOLVED] Play MP3 File in Console Application
No offense minitech but the code i was implying to have a look was doing da job,if by synchronous you meant to be playing with the console and the mp3,wav whatever to get the keys and act accordingly. :)
If that was not what you wanted my mistake. :wave:
Re: [RESOLVED] Play MP3 File in Console Application
No, from what I understood of the sentence you are thinking of "asynchronous". I didn't want to close the sound before it had even started playing!
Re: [RESOLVED] Play MP3 File in Console Application
Nobody wanted to close the sound before playing(except if it was some spice girls tune :D ) .Well with the code i provide you can start,stop,mute,pause the file and the console closes only with escape or with the mouse on the X button.You can modify it also to your needs (p.e. load another file).
Anyway you probably got what you needed so no point on continuing.
Cheers.