Results 1 to 15 of 15

Thread: playing mp3 files [Resloved]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194

    playing mp3 files [Resloved]

    all I want to do is play an mp3 file when a cmd button is clicked - but I have an uneasy feeling that this is not going to be as simple as I would like it to be.



    can I zip up the mp3 files with the application? do I need to include a player of some type ? or are there commands to search a pc to look for their player???????

    Could someone give me a pointer where to start...

    many thanks
    Last edited by mbonfyre; Oct 30th, 2002 at 04:01 PM.

  2. #2
    Junior Member -_MAD-HATTAH_-'s Avatar
    Join Date
    Sep 2002
    Location
    PHX AZ
    Posts
    25
    Would u perfer it to play the MP3 in another program (ie Windows Media Player) Or ONLY from your program?
    -_MAD-HATTAH_-

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    It doesn't really matter to me, although the guys who will be using this would probably prefer their default players. At the end of the day I am making this for them as a favour (and good practise for me) so whatever will be easiest!

  4. #4
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249
    This API will open a file using the system default executable for the file type:

    This goes in a module:

    VB Code:
    1. Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    2.     ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal _
    3.     lpDirectory As String, ByVal nShowCmd As Long) As Long
    4. Public Const SW_MAXIMIZE = 3
    5. Public Const SW_MINIMIZE = 6
    6. Public Const SW_RESTORE = 9


    This goes in the Command Button Click event:

    VB Code:
    1. Dim retVal as long
    2. Dim sMP3 as string
    3.  
    4. sMP3 = "path to some mp3 file"
    5.  
    6. retval = ShellExecute(Form1.hWnd, "open", sMP3, "-fast", App.Path, _
    7.         SW_MAXIMIZE)
    8.  
    9. ' note that Form1.hwnd is replaced with the
    10. ' name of your form that is making the call (frmMain.hwnd for example).


    Check out :http://216.26.168.92/vbapi/ref/s/shellexecute.html

    For a full discussion. Also, you may like to look at the ShellExecuteEX API. It is more powerful and allows you more control of the function.

    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    tried your code and got this line highlighted:

    retVal = ShellExecute(frmPlaylist.hwnd, , "open", sMP3, "-fast", App.Path, _

    and the message:

    Argument not optional....

    any ideas?

  6. #6
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249
    Originally posted by mbonfyre
    tried your code and got this line highlighted:

    retVal = ShellExecute(frmPlaylist.hwnd, , "open", sMP3, "-fast", App.Path, _

    and the message:

    Argument not optional....

    any ideas?

    Ahhhhh!!!!!
    It's that damn pesky SW_MAXIMIZE....LOL
    Add the SW_MAXIMIZE constant to the end on the line

    VB Code:
    1. retval = ShellExecute(Form1.hwnd, "open", sMP3, "-fast", "C:\Temp\", SW_MAXIMIZE)

    I just tested it and it opened WinAmp and played the MP3.
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    this may sound dumb, but what does "c:\Temp\" refer to?

    retval = ShellExecute(Form1.hwnd, "open", sMP3, "-fast", "C:\Temp\", SW_MAXIMIZE)
    Obviously, I still have not got it going!

  8. #8
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249
    Now, it you want to add a touch of flair to your efforts, why not label the comman button with the default system player?

    This is from one of my projects. Change the control references to suit your system. This gives you the idea:

    Module Code:

    VB Code:
    1. Public Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, _
    2.     ByVal lpDirectory As String, _
    3.     ByVal lpResult As String) As Long

    Form Load (or whereever you want to do it) Code:

    VB Code:
    1. Dim sResult As String
    2. Dim lPos    As Long
    3. Dim lMyResult As Long
    4.    
    5. sResult = String(255, Chr(0))
    6. lMyResult = FindExecutable(MP3Path, vbNullString, sResult)
    7. sResult = Trim(Replace(sResult, "/dde", "", 1))
    8. sResult = Trim(Replace(sResult, vbNullChar, "", 1))
    9.    
    10.    
    11. lPos = InStr(strResult, "wmplayer.exe")
    12. If lPos <> 0 Then
    13.         Command1.Caption = "Play with Media Player"
    14.         Exit Function
    15. End If
    16.    
    17. lPos = InStr(strResult, "winamp.exe")
    18. If lPos <> 0 Then
    19.         Command1.Caption = "Play with Winamp"      
    20. End If
    Last edited by PhilRob56; Oct 30th, 2002 at 03:50 PM.
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  9. #9
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249
    Originally posted by mbonfyre
    this may sound dumb, but what does "c:\Temp\" refer to?



    Obviously, I still have not got it going!
    Not dumb!
    Apparently it is a folder for the API to use - like a temp area. I don't think it really matters where it is. I just pointed it at Temp.


    Hmmm...Still the same error?
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    Flair would be great, but I think I better keep trying to get it to work before I start trying to get flash!

    my code:

    Private Sub Command1_Click()

    Dim retVal As Long
    Dim sMP3 As String

    sMP3 = "C:\Program Files\KaZaA\My Shared Folder\Alien Antfarm - Smooth Criminal.mp3"

    retVal = ShellExecute(frmPlaylist.hwnd, , "open", sMP3, "-fast", "C:\Temp\", SW_MAXIMIZE)


    End Sub

    yes I have included the other code in a module...

    any further ideas (please!)

  11. #11
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249
    Ok, let me look...
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    Sussed it!, that extra comma!!!

    thanks for your help

  13. #13
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249

    Geeze!!!

    Couldn't find it for the life of me. I even created your directory structure and named an MP3 Alien antfarm....

    Still couldn't get it to work....and then I saw it...

    two (2) commas after frmPlaylist.hwnd - ....... , , "open".......


    VB Code:
    1. retVal = ShellExecute(frmPlaylist.hwnd, "open", sMP3, "-fast", "C:\Temp\", SW_MAXIMIZE)

    Paste this in...it does work...even on Alient Antfarms....
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  14. #14
    Addicted Member PhilRob56's Avatar
    Join Date
    Oct 2002
    Location
    New York
    Posts
    249

    LOL

    You beat me!!


    Now go and add that extra touch....it'll be cool!
    Some days you're the dog,
    and some days you're the hydrant.


    VB6 Enterprise

  15. #15
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    You can pass vbNullString in the place of "C:\temp\" and it will work. This is usually how I call it:

    ShellExecute hwnd, "open", sMP3 ,vbNullString, vbNullString, 1
    <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