Results 1 to 22 of 22

Thread: Mp3

  1. #1
    appi101
    Guest
    Hi

    How do I play an MP3 file, get info abt it like the tag information and all that?

  2. #2
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    You can use the Windows Media player contol to play mp3 files.
    Code:
    MediaPlayer1.FileName ="Mp3file.mp3"
    I have a sample program that shows you how to extract the ID3 info from a file. I can send it when I get home...if you want to.
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  3. #3
    Chavez
    Guest

  4. #4
    appi101
    Guest
    Thanks. The program would be great if you could post it or send it to me.

  5. #5
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Add this to a module:

    Code:
    Public Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
    Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Declare Function ReleaseCapture Lib "user32" () As Long
    Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2
    Public TheFileName As String
    
    
    
    Public Function IsItPlaying() As Boolean
    Static yn As String * 30
        mciSendString "status MP3Play mode", yn, Len(yn), 0
        IsPlaying = (Mid$(yn, 1, 7) = "playing")
    End Function
    
    Public Function mp3Play(FileName As String)
    Dim cmdToDo As String * 255
    Dim dwReturn As Long
    Dim ret As String * 128
    
    Dim tmp As String * 255
    Dim lenShort As Long
    Dim ShortPathAndFie As String
        
        If Dir(FileName) = "" Then
            mmOpen = "Error with input file"
            Exit Function
        End If
        lenShort = GetShortPathName(FileName, tmp, 255)
        ShortPathAndFie = Left$(tmp, lenShort)
        glo_hWnd = hwnd
        cmdToDo = "open " & ShortPathAndFie & " type MPEGVideo Alias MP3Play"
        dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&)
    
        If dwReturn <> 0 Then  'not success
            mciGetErrorString dwReturn, ret, 128
            mmOpen = ret
            MsgBox ret, vbCritical
            Exit Function
        End If
        
        mmOpen = "Success"
        mciSendString "play MP3Play", 0, 0, 0
    End Function
    
    Public Function mp3Pause()
        mciSendString "pause MP3Play", 0, 0, 0
    End Function
    
    Public Function mp3Stop() As String
        mciSendString "stop MP3Play", 0, 0, 0
        mciSendString "close MP3Play", 0, 0, 0
    End Function
    
    Public Function PositionInSec()
    Static PIS As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play position", PIS, Len(PIS), 0
        PositionInSec = Round(Mid$(PIS, 1, Len(PIS)) / 1000)
    End Function
    
    Public Function Position()
    Static P As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play position", P, Len(P), 0
        sec = Round(Mid$(P, 1, Len(P)) / 1000)
        If sec < 60 Then Position = "0:" & Format(sec, "00")
        If sec > 59 Then
            mins = Int(sec / 60)
            sec = sec - (mins * 60)
            Position = Format(mins, "00") & ":" & Format(sec, "00")
        End If
    End Function
    
    Public Function LengthInSec()
    Static L As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play length", L, Len(s), 0
        LengthInSec = Round(Val(Mid$(L, 1, Len(L))) / 1000) 'Round(CInt(Mid$(s, 1, Len(s))) / 1000)
    End Function
    
    Public Function Length()
    Static L As String * 30
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        mciSendString "status MP3Play length", L, Len(L), 0
        sec = Round(Val(Mid$(L, 1, Len(L))) / 1000) 'Round(CInt(Mid$(l, 1, Len(l))) / 1000)
        If sec < 60 Then Length = "0:" & Format(sec, "00")
        If sec > 59 Then
            mins = Int(sec / 60)
            sec = sec - (mins * 60)
            Length = Format(mins, "00") & ":" & Format(sec, "00")
        End If
    End Function
    
    
    Public Function SeekTo(Second)
        mciSendString "set MP3Play time format milliseconds", 0, 0, 0
        If IsItPlaying = True Then mciSendString "play MP3Play from " & Second, 0, 0, 0
        If IsItPlaying = False Then mciSendString "seek MP3Play to " & Second, 0, 0, 0
    End Function
    
    
    
    VBBrowser v2.2.1
    <removed by admin>

  6. #6
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    The above will play an MP3 file, without the WMP control.

    This class module will help you get the tag information.

    To use it you go like this:

    Code:
    Dim mp3 As New clsID3
    
    Private Sub Command1_Click()
    mp3.Filename = "Yourfile.mp3"
    MsgBox mp3.Artist
    MsgBox mp3.Title
    MsgBox mp3.Album
    MsgBox mp3.Comment
    MsgBox mp3.Genre
    MsgBox mp3.Year
    
    End Sub
    VBBrowser v2.2.1
    Attached Files Attached Files
    <removed by admin>

  7. #7
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks for the code..

    could this be used so that audio files could be played one after the other?

    is there a way to track down positions/marks so that I could program code to play an mp3 file, then automaticly know when that file is finished so that it can start to play another mp3 file (and so on)..


    also I am guessing I do not need any speciall ocx or dll to use this code. Just the ussuall stuff in any Windows (95/98/Me) plus VB runtime files of cource.


    thanks!
    Abdul
    1+1=3
    make life simple, use a calculator!

  8. #8
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks again!

    am puzziled a little now..

    this code that he posted..

    I tried it.. it works okay.. but..

    hmmm.... it seems to play ALL Mp3 files and .wav and EVEN .wma files !!!!! how??

    All in the tiny code that is used above????


    I mean.. I have a feeling that the code is relying on some other external file/coder that is doing the business.

    if so... do I need to worry about this? would what ever its relying on be all there on the end users computer without me worrying about what extra files to include in my packaged setup??

    basicly... would audio files played using the above code work on ANY windows based system (win95/98/Me) With just the VB runtime files of coure.

    any adivse?

    anyone??

    thanks guys!
    Abdul
    1+1=3
    make life simple, use a calculator!

  9. #9
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    LoCal
    Posts
    280
    Abdul,

    MidgetsBro's code is using the MCI (multimedia control interface) API calls.
    I suppose there is a chance that you'd need to distribute the latest version of the
    winmm.dll file with your app but that's just a normal windows file, not a third-party ocx.
    YOU may need to download the latest version of MediaPlayer to get the file, I don't know,
    I'm not sure where it comes from. You could try distributing your app to a new computer and
    see if it works...

    I imagine it should work with 98 and definitely with ME but that's just my feeling.
    Achichincle

    VB6 (VSEE SP5, W2KPro)
    ASP
    HTML

  10. #10
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks a lot,

    I am on WinMe.

    my winmm.dll is version 4.90.3000

    could you please check your version, also which OS your running it on?

    if anyone else could also do that..


    I am gussing that if I install it on older (i.e. Win98) then the older winmm.dll would be upgraded to the new winmm.dll and that would be upgraded. without any compatiblilty problems..


    thanks!
    Abdul
    1+1=3
    make life simple, use a calculator!

  11. #11
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks a lot,

    I am on WinMe.

    my winmm.dll is version 4.90.3000

    could you please check your version, also which OS your running it on?

    if anyone else could also do that..


    I am gussing that if I install it on older (i.e. Win98) then the older winmm.dll would be upgraded to the new winmm.dll and that would be upgraded. without any compatiblilty problems..


    thanks!
    Abdul
    1+1=3
    make life simple, use a calculator!

  12. #12
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks a lot,

    I am on WinMe.

    my winmm.dll is version 4.90.3000

    could you please check your version, also which OS your running it on?

    if anyone else could also do that..


    I am gussing that if I install it on older (i.e. Win98) then the older winmm.dll would be upgraded to the new winmm.dll and that would be upgraded. without any compatiblilty problems..


    thanks!
    Abdul
    1+1=3
    make life simple, use a calculator!

  13. #13
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks a lot,

    I am on WinMe.

    my winmm.dll is version 4.90.3000

    could you please check your version, also which OS your running it on?

    if anyone else could also do that..


    I am gussing that if I install it on older (i.e. Win98) then the older winmm.dll would be upgraded to the new winmm.dll and that would be upgraded. without any compatiblilty problems..


    thanks!
    Abdul
    1+1=3
    make life simple, use a calculator!

  14. #14
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks a lot,

    I am on WinMe.

    my winmm.dll is version 4.90.3000

    could you please check your version, also which OS your running it on?

    if anyone else could also do that..


    I am gussing that if I install it on older (i.e. Win98) then the older winmm.dll would be upgraded to the new winmm.dll and that would be upgraded. without any compatiblilty problems..


    thanks!
    Abdul
    1+1=3
    make life simple, use a calculator!

  15. #15
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    LoCal
    Posts
    280
    No problem but how do I find the DLL version? I'm on Win 200 Pro.
    Achichincle

    VB6 (VSEE SP5, W2KPro)
    ASP
    HTML

  16. #16
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks

    could you not just find it, like do a search in teh windows find feature

    it should in the system32 folder in the winnt (in your case I think)

    but you can also let windows search for it

    could everyone else reading this please do that with their windows...

    that would be greatly appreciated

    thanks again!
    Abdul
    1+1=3
    make life simple, use a calculator!

  17. #17
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    LoCal
    Posts
    280
    Sorry I was having a 'brain fart'.

    Version 5.0.2161.1 - Win 200 Pro

    Do a search on http://msdn.microsoft.com for winmm.dll and one of the results takes you to their DLL help section which will then list the versions shipped for the different Windows versions.
    Achichincle

    VB6 (VSEE SP5, W2KPro)
    ASP
    HTML

  18. #18
    Chavez
    Guest
    I am currently running Win98 SE, and its version of the
    file is 4.03.1998, which I got by going to its file
    properties and clicking on the version tab.

  19. #19
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks guys..

    will contiune more in my research about this.

    (btw. sorry for multimple posts earlier.. didint know they went through)

    Abdul
    1+1=3
    make life simple, use a calculator!

  20. #20
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    I know this works on my Win98SE, Win98, Win2K, and Win95B machines, so I think any of the latest versions of winmm.dll can handle it.
    <removed by admin>

  21. #21
    Chavez
    Guest
    MidgetBro,
    How could I get the length of an mp3 while another mp3 is playing??

    From your code above, in order to get the length of file, it has to be playing.
    And what I want to do is allow the user to add another song to a playlist which includes listing the added file's length and to do all this while the current song is playing.


    Any ideas?

  22. #22
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    This module allows you to get the duration of the file. I haven't used it much, but it should work for what you want it to do.

    This is how you use it
    Code:
    Call ReadMP3("Filename.mp3", True, True)
    MsgBox GetMP3Info.Artist
    MsgBox GetMP3Info.Songname
    Attached Files Attached Files
    <removed by admin>

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