locked
how to play WMP/MP3?

    Question

  • what code is needed to play MP3 song (resource) in form? (VB 2005 EXPRESS EDITION)
    Friday, March 09, 2007 5:06 PM

Answers

  • First ...as long as the extensions are registered on the computer it will open the associated application to play the files...avi, mp3, wmp..etc...If they are not registered then you must call a program that will handle the file (media player for example) and then pass the file as a argument...now as for as the error your getting...the above code is its own method and you can not insert that complete code within another method!
    Friday, March 09, 2007 9:48 PM
  • Or, if you do not want a visible Windows Media Player:

    Public Class Form1

        ' Play an MP3 file with a hidden media player

     

        ' Example Uses embedded resource file

        ' named "The Beatles - And I Love Her.mp3"

     

        ' Add a Windows Media Player control to your form

        ' then use the code below

     

        Private Sub Form1_Load(ByVal sender As Object, _

        ByVal e As System.EventArgs) Handles Me.Load

            Dim b As Byte() = My.Resources.The_Beatles___And_I_Love_Her

     

            Dim TempFile As System.IO.FileStream = IO.File.Create("c:\song.mp3")

     

            TempFile.Write(b, 0, b.Length)

            TempFile.Close()

     

            AxWindowsMediaPlayer1.Visible = False

            AxWindowsMediaPlayer1.URL = "c:\song.mp3"

            AxWindowsMediaPlayer1.settings.setMode("loop", True)

     

        End Sub

    End Class

     

     

    Saturday, March 10, 2007 1:54 AM

All replies

  • Write Out Resource File and then Execute:

    Public Sub RunMyResource()
    Dim b As Byte() = My.Resources.
    MyAudio

    Dim TheFIlePath As String = "C:\MyAudio.mp3"

    Dim TempFile As System.IO.FileStream = IO.File.Create(TheFIlePath)
    TempFile.Write(b, 0, b.Length)
    TempFile.Close()
    Process.Start(TheFIlePath)
    End Sub

    Friday, March 09, 2007 5:22 PM
  • but then it opens WMP file, and i want it to play on application, not opening another file. and i cannot enter : "Public Sub RunMyResource()" because there's error: "Statement cannot appear within a method body. End of method assumed."
    .
    Friday, March 09, 2007 7:12 PM
  • First ...as long as the extensions are registered on the computer it will open the associated application to play the files...avi, mp3, wmp..etc...If they are not registered then you must call a program that will handle the file (media player for example) and then pass the file as a argument...now as for as the error your getting...the above code is its own method and you can not insert that complete code within another method!
    Friday, March 09, 2007 9:48 PM
  • If you can convert to wav files, it is easy.

    Otherwise, check out this link:

    http://www.codeproject.com/cs/media/nBASS.asp

    If you need help translating the C# code into VB, let me know.

    Jonathan

    Friday, March 09, 2007 10:24 PM
  • Or, if you do not want a visible Windows Media Player:

    Public Class Form1

        ' Play an MP3 file with a hidden media player

     

        ' Example Uses embedded resource file

        ' named "The Beatles - And I Love Her.mp3"

     

        ' Add a Windows Media Player control to your form

        ' then use the code below

     

        Private Sub Form1_Load(ByVal sender As Object, _

        ByVal e As System.EventArgs) Handles Me.Load

            Dim b As Byte() = My.Resources.The_Beatles___And_I_Love_Her

     

            Dim TempFile As System.IO.FileStream = IO.File.Create("c:\song.mp3")

     

            TempFile.Write(b, 0, b.Length)

            TempFile.Close()

     

            AxWindowsMediaPlayer1.Visible = False

            AxWindowsMediaPlayer1.URL = "c:\song.mp3"

            AxWindowsMediaPlayer1.settings.setMode("loop", True)

     

        End Sub

    End Class

     

     

    Saturday, March 10, 2007 1:54 AM
  • That's pretty cool.
    Tuesday, March 13, 2007 12:33 AM
  • Hi Guys if you want to play wmp/*.mp3 files in your vb 6 application then goto to the project menu tick the windows media player click apply and create  the wmp in the vb form window and create a command button named cmd_play and in the click event of cmd_play

    put this coding

     

    wmp.URL = "full path of the song file\song.mp3"

    run the project

    Enjoy

    Neeru

    Thursday, July 12, 2007 10:00 AM
  • I have looked for ways to play files without using wmp because you have to have an agreement with microsoft to use it in a finished application.  The cost i believe is around $10,000.

     

    I found some great projects that will show you how to play all types of files without having to rely on wmp.

    Here is the link    http://www.vbcodesource.com/exampleNet.html

     

    The ones that i have found that work well are:

    audiovideodx    -  directx 9 for audio and video     plays wmv and mpeg   (not sure what other video)  and also most audio

    musicmodule  -  plays wav, wma, mp3, midi           creates playlists you can save

    both of these have controls for volume, balance and position

     

    There are two more that work fairly well for wav files

    playwavefileex

    directsoundex  -  this one has options for playing asynchronous and looping

    Thursday, July 12, 2007 2:41 PM