|
-
Oct 30th, 2002, 02:01 PM
#1
Thread Starter
Addicted Member
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.
-
Oct 30th, 2002, 02:04 PM
#2
Junior Member
Would u perfer it to play the MP3 in another program (ie Windows Media Player) Or ONLY from your program?
-
Oct 30th, 2002, 02:08 PM
#3
Thread Starter
Addicted Member
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!
-
Oct 30th, 2002, 02:45 PM
#4
Addicted Member
This API will open a file using the system default executable for the file type:
This goes in a module:
VB Code:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal _
lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_RESTORE = 9
This goes in the Command Button Click event:
VB Code:
Dim retVal as long
Dim sMP3 as string
sMP3 = "path to some mp3 file"
retval = ShellExecute(Form1.hWnd, "open", sMP3, "-fast", App.Path, _
SW_MAXIMIZE)
' note that Form1.hwnd is replaced with the
' 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
-
Oct 30th, 2002, 03:23 PM
#5
Thread Starter
Addicted Member
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?
-
Oct 30th, 2002, 03:32 PM
#6
Addicted Member
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:
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
-
Oct 30th, 2002, 03:41 PM
#7
Thread Starter
Addicted Member
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!
-
Oct 30th, 2002, 03:43 PM
#8
Addicted Member
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:
Public Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) As Long
Form Load (or whereever you want to do it) Code:
VB Code:
Dim sResult As String
Dim lPos As Long
Dim lMyResult As Long
sResult = String(255, Chr(0))
lMyResult = FindExecutable(MP3Path, vbNullString, sResult)
sResult = Trim(Replace(sResult, "/dde", "", 1))
sResult = Trim(Replace(sResult, vbNullChar, "", 1))
lPos = InStr(strResult, "wmplayer.exe")
If lPos <> 0 Then
Command1.Caption = "Play with Media Player"
Exit Function
End If
lPos = InStr(strResult, "winamp.exe")
If lPos <> 0 Then
Command1.Caption = "Play with Winamp"
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
-
Oct 30th, 2002, 03:45 PM
#9
Addicted Member
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
-
Oct 30th, 2002, 03:52 PM
#10
Thread Starter
Addicted Member
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!)
-
Oct 30th, 2002, 03:54 PM
#11
Addicted Member
Some days you're the dog,
and some days you're the hydrant.
VB6 Enterprise
-
Oct 30th, 2002, 03:58 PM
#12
Thread Starter
Addicted Member
Sussed it!, that extra comma!!!
thanks for your help
-
Oct 30th, 2002, 04:10 PM
#13
Addicted Member
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:
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
-
Oct 30th, 2002, 04:11 PM
#14
Addicted Member
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
-
Oct 30th, 2002, 04:14 PM
#15
PowerPoster
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|