|
-
Jan 23rd, 2011, 07:39 PM
#1
Thread Starter
Stack Overflow moderator
[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!
-
Jan 23rd, 2011, 11:41 PM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 24th, 2011, 12:30 AM
#3
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 )you can see my application here:
http://www.vbforums.com/showthread.php?p=3948319
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jan 25th, 2011, 09:44 PM
#4
Thread Starter
Stack Overflow moderator
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!)
-
Jan 27th, 2011, 08:05 PM
#5
Thread Starter
Stack Overflow moderator
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
-
Jan 27th, 2011, 09:29 PM
#6
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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jan 28th, 2011, 07:07 PM
#7
Thread Starter
Stack Overflow moderator
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!
-
Jan 28th, 2011, 07:22 PM
#8
Re: [RESOLVED] Play MP3 File in Console Application
Nobody wanted to close the sound before playing(except if it was some spice girls tune ) .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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
Tags for this Thread
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
|