well basically like the topic says How do i go about playing mp3 in vb.net 05 if i could get a little help on this i would appreciate it.
Printable View
well basically like the topic says How do i go about playing mp3 in vb.net 05 if i could get a little help on this i would appreciate it.
.NET 2.0 has the SoundPlayer class but I think it only handles WAV files. For an MP3 I'd guess that your best bet would be to use Windows Media Player. You can add a reference to wmp.dll to your project from the COM tab and then create an instance of the WMPLib.WindowsMediaPlayer. Note that that class is for use without an interface. The AxWMPLib.AxWindowsMediaPlayer class is the ActiveX control that does provide an interface.
mciSendStrings are a bit more versatile. Link:
http://msdn.microsoft.com/library/de...2_setaudio.asp
For example, you could do something like this to play a file:
Class MP3:
VB Code:
Option Strict Off Option Explicit On Imports System.IO Imports System.Xml Friend Class MP3Class Dim Id3 As New Id3() ' 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 Public Declare Function auxGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal lpdwVolume As Long) As Long Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Integer) As Integer <System.Runtime.InteropServices.DllImport("kernel32.dll")> Shared Function _ GetShortPathName(ByVal lpszLongPath As String, _ ByVal lpszShortPath As System.Text.StringBuilder, _ ByVal cchBuffer As Integer) As Integer End Function <System.Runtime.InteropServices.DllImport("winmm.dll")> Shared Function _ PlaySound(ByVal lpszName As String, ByVal hModule As Integer, _ ByVal dwFlags As Integer) As Integer End Function Public MP3File As String Dim TheFile As String Sub MP3Play() Try mciSendString("close " & TheFile, CStr(0), 0, 0) TheFile = Chr(34) & Trim(MP3File) & Chr(34) mciSendString("open " & TheFile, CStr(0), 0, 0) mciSendString("play " & TheFile, "", 0, 0) Catch MsgBox("There was an error trying to play " & GetLastBackSlash(MP3File) & ".", MsgBoxStyle.Critical, "Error!") End Try End Sub End Class
Then, in your form's code, write something like:
VB Code:
Dim MP3 As New MP3Class() Private Sub btnPlay_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click 'You could make the thing below any file you want. If you make it more complex, you could use items from a listbox that serves as a sort of playlist MP3.MP3File = "C:\blahblah.mp3" MP3.MP3Play() End Sub
I have created a complex media player with ~4500 lines of code. It can play .asf, .avi, .bmp, .gif, .jpg, .jpeg, .png, .ico, .cda, .mp3, .mpeg, .wma, and .wmv. It can also read ASF, M3U, and WPL playlist files. Using the above code along with info provided in my link, you should have a nice start.
What would you know about using mciSendString? :D