Results 1 to 4 of 4

Thread: How do i go about playing mp3 in vb.net 05

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    71

    How do i go about playing mp3 in vb.net 05

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How do i go about playing mp3 in vb.net 05

    .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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Addicted Member
    Join Date
    Jul 2005
    Location
    Chicago
    Posts
    202

    Re: How do i go about playing mp3 in vb.net 05

    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:
    1. Option Strict Off
    2. Option Explicit On
    3. Imports System.IO
    4. Imports System.Xml
    5. Friend Class MP3Class
    6.     Dim Id3 As New Id3()
    7.     '
    8.     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
    9.     Public Declare Function auxGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal lpdwVolume As Long) As Long
    10.     Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Integer) As Integer
    11.     <System.Runtime.InteropServices.DllImport("kernel32.dll")> Shared Function _
    12.         GetShortPathName(ByVal lpszLongPath As String, _
    13.         ByVal lpszShortPath As System.Text.StringBuilder, _
    14.         ByVal cchBuffer As Integer) As Integer
    15.     End Function
    16.     <System.Runtime.InteropServices.DllImport("winmm.dll")> Shared Function _
    17.         PlaySound(ByVal lpszName As String, ByVal hModule As Integer, _
    18.         ByVal dwFlags As Integer) As Integer
    19.     End Function
    20.  
    21.     Public MP3File As String
    22.     Dim TheFile As String
    23.  
    24. Sub MP3Play()
    25.         Try
    26.             mciSendString("close " & TheFile, CStr(0), 0, 0)
    27.             TheFile = Chr(34) & Trim(MP3File) & Chr(34)
    28.             mciSendString("open " & TheFile, CStr(0), 0, 0)
    29.             mciSendString("play " & TheFile, "", 0, 0)
    30.         Catch
    31.             MsgBox("There was an error trying to play " & GetLastBackSlash(MP3File) & ".", MsgBoxStyle.Critical, "Error!")
    32.         End Try
    33.  
    34.     End Sub
    35.  
    36. End Class

    Then, in your form's code, write something like:
    VB Code:
    1. Dim MP3 As New MP3Class()
    2.  
    3. Private Sub btnPlay_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
    4. '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
    5.    MP3.MP3File = "C:\blahblah.mp3"
    6.    MP3.MP3Play()
    7. 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.
    A programmer is a person who fixes a problem you did not know you had in a way that you cannot understand.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How do i go about playing mp3 in vb.net 05

    What would you know about using mciSendString?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width