Results 1 to 11 of 11

Thread: Playing mp3's

  1. #1

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    How can i do this?

    r0ach™
    Don't forget to rate the post

  2. #2
    Guest
    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

  3. #3

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    Thank you!
    Thank you!
    Thank you!

    r0ach™
    Don't forget to rate the post

  4. #4
    Guest
    Your Welcome

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    denniswrenn

    I don't have my system as my hard drive has decided to kick the bucket, so I can't check this out right away. I have tried one or two sets of code in VB for playing mp3 files but found most of them really thin as they seem to come through the pc speakers and not the system speakers...ie. no bass speaker, no tweeters, just more like glorified mono. Does your code pump it out if your system has the capabilies?

    PS...over 1000 mp3 files toasted with my drive failure...real bummer!
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    Guest
    damn!!!!!
    1000 MP3's?

    how long did it take you to get those??

    I only have about 15 at the most...

    and always back your stuff up....

    its costing me a bit more because I use really nice Sony CDR's but I back my HDD up at least once a month.

    and I am glad too, because I had to reformat about a month ago.... I would have lost EVERYTHING!
    all my ICQ contacts, all my email(POP email coming through Outlook)
    all of my pictures, this may not sound big, but I like to collect pictures(jpgs and stuff) I have over 2000 images... over 500mb of images...
    I also have a lot of software and code samples....

    ok ummmm about your question,

    this sounds exactly like winamp does.
    I am not really sure what it is played through.. but it sounds good enough for me


  7. #7
    Guest

    Question HeSaidJoe

    what was the other code you saw that didnt work very good?

  8. #8

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    btw. There were a few undeclared variables and spelling errors. I fixed it, 'cept for the glo_hWnd = hWnd. I just commented that out.

    Works great. I would just have to figure out some goodies, like resuming play after a pause and how to read the ID3 Tag, etc., etc.

    1000 Mp3's are a terrible loss. I have about 60.

    r0ach™
    Don't forget to rate the post

  9. #9
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Ok..I'll copy your code and give it a twirl next week or whenever I get my drive back.

    Time..it takes only a minuite or two at most to download an mp3 file (Sympatico High Speed coupled with a fast PC)...where it hurt was in the fact that I had converted all the songs I thought good from my collection of over 200 cd's and that takes a lot of time to flip flop the CD and then convert from wav to mp3 as 1000 wavs would be more than my 20 G drive would hold. Then, you have to swich back to wav format if you want to make a compilation of varius artist playable on cd players, which incidentally was the plan.

    I back up most stuff with the help of my CD Burner, but the mp3 folder was over 3 Gigs in size so I had to leave it out.

    As they say stuff happens...I'm still alive and well and can't see any reason why I can't get it all back in due time.

    Thanks,
    Later,
    Wayne
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  10. #10
    Guest
    damn your lucky it usually takes me about 40min to download a song.....

  11. #11
    New Member
    Join Date
    Jul 2000
    Location
    Darmstadt, Germany
    Posts
    1

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