-
[RESOLVED] Is there something that acts and loops like sndPlaySOund, but can play .mp3 files?
I need something that can loop perfectly like sndPlaySound does, but i also need something that can play .mp3 files... I dont want to have to use a control though. Any ideas?
If i have to use a control(like the ones in the tools...), then let me know.
The problem is that the .wav files are just WAY to big. I put them into a .res, and it makes the project HUGE. So, i want to try .mp3. Tried it with sndPlaySound(ik u cant use 'em. Just foolin around) and of course didnt work.... so.. yeah. plz help. i need this help so bad!
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
MMC (Microsoft Multimedia Control) should be able to play *.mp3's...
Good Luck
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
yeah, but how would u get those to loop, like start again RIGHT as the song ends?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
mmc uses mci, there is a "repeat" command for mcisendstring,
but if i'm not mistaken,
there is some delay between each loop.
you can try it, the command is:
Code:
Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
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
Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Public Const MAX_PATH = 260
Public LastMCIError As Long
Public Function LenZ(ByVal Str1 As String) As Integer
LenZ = InStr(1, Str1$, vbNullChar)
End Function
Public Function RTrimNull(ByVal Str1 As String) As String
Dim iNum As Integer
iNum = LenZ(Str1$)
If iNum <= 0 Then
iNum = InStr(1, Str1$, Chr(13))
If iNum <= 0 Then
RTrimNull$ = RTrim(Str1$)
Exit Function
End If
End If
RTrimNull$ = Left(Str1$, iNum - 1)
End Function
Public Function GetShortPath(ByVal Str1 As String) As String
Dim strBuf As String * MAX_PATH
Call GetShortPathName(Str1$, strBuf$, MAX_PATH - 1)
GetShortPath$ = RTrimNull$(strBuf$)
End Function
Public Function MCIGetError(Optional ByVal lErr As Long = -1) As String
Dim Str1 As String * 1024
If lErr = -1 Then lErr = LastMCIError
'retrieve the error string
Call mciGetErrorString(lErr, Str1$, 1023)
'strip off the trailing spaces
MCIGetError$ = RTrimNull$(Str1$)
End Function
Private Function Mci_(ByVal sCommand As String, Optional Ret As Long = vbNull) As String
Dim Str1 As String * 512
LastMCIError = mciSendString(sCommand, Str1$, 511, 0)
If Ret <> vbNull Then Ret = LastMCIError
Mci_$ = RTrimNull$(Str1$)
End Function
Function MCIOpen(ByVal fName As String, Optional ByVal sDevice As String = "mpegvideo") As Boolean
Dim Num1 As Long
Call Mci_$("open " & GetShortPath$(fName) & " type " & sDevice$ & " alias MediaStream", Num1)
Call Mci_$("set MediaStream time format milliseconds")
If Num1 Then MCIOpen = True
End Function
Sub Main
MCIOpen "my_mp3.mp3"
mci_ "play MediaStream repeat"
End Sub
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Yeah. there is a time laps b4 it loops again... i dont rly want that.... is there another way?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
for mp3 i think the repeat method can be good enough.
you can also try these methods:
using a timer and check the playing state.
using notify command, mci will call your form, when it finish playing.
i checked these 2 methods with tiny wav files and it doesn't work as i want,
sndplay does it for waves the best, except that it can't play more than one file per app.
but as i said for mp3, i think the mci is good enough.
you can also try other dlls,
on my signature there is a very good audio library, that has many features, like effects, etc...
also there is a very good app in the forum code bank, called "monoton".
this a full audio library, written in vb, and it's very good.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Put this code in module:wave:
Code:
Option Explicit
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private 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
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private 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
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Sub Pause()
Call mciSendString("pause mp3play", 0, 0, 0)
End Sub
Public Sub Play(MpegAudio As String)
Dim lngLen As Long, strShort As String * 255, strPlay As String
Call mciSendString("stop mp3play", 0, 0, 0)
Call mciSendString("close mp3play", 0, 0, 0)
lngLen = GetShortPathName(MpegAudio, strShort, 255)
strPlay = Left(strShort, lngLen)
Call mciSendString("open " & strPlay & " type mpegvideo alias mp3play", 0, 0, 0)
Call mciSendString("play mp3play", 0, 0, 0)
End Sub
Private Sub Resume_Play()
Call mciSendString("resume mp3play", 0, 0, 0)
End Sub
Private Sub Speed_Slow()
Call mciSendString("set mp3play speed 500", 0, 0, 0)
End Sub
Private Sub Speed_Normal()
Call mciSendString("set mp3play speed 1000", 0, 0, 0)
End Sub
Private Sub Speed_Fast()
Call mciSendString("set mp3play speed 1500", 0, 0, 0)
End Sub
Private Sub StopIt()
Call mciSendString("stop mp3play", 0, 0, 0)
Call mciSendString("close all", 0, 0, 0)
End Sub
Private Function length() As String
Dim LengthA As String * 30
Call mciSendString("status mp3play length", LengthA, Len(LengthA), 0)
length = LengthA
End Function
Private Function Position() As String
Dim PositionA As String * 30
Call mciSendString("status mp3play position", PositionA, Len(PositionA), 0)
Position = PositionA
End Function
Private Sub Mute(isMute As Boolean)
If isMute = True Then
Call mciSendString("set mp3play audio all off", 0, 0, 0)
ElseIf isMute = False Then
Call mciSendString("set mp3play audio all on", 0, 0, 0)
End If
End Sub
Private Sub PauseRsm(rSm As Boolean)
If rSm = True Then
Call Pause
ElseIf rSm = False Then
Call Resume_Play
End If
End Sub
Usage is here ... in the form write this code ...:eek2:
Code:
Private Sub Form_Load ()
Play("c:\windows\help\mysound.mp3") ' your mp3 file path
End Sub
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
okay tricker32.... how does this help me loop? xD
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Quote:
Originally Posted by
Gamemaster1494
okay tricker32.... how does this help me loop? xD
One post I found said to add repeat to the play string,...
Call mciSendString("play mp3play repeat", 0, 0, 0)
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
What about having your app download the .wav and/or .mp3 from the net.
Play("Http://www.windows.com/help/mysound.mp3")
Play("Http://www.windows.com/help/mysound.wav")
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Hmm........... well, i was kinda wanting to avoid the overall size of the game. im using the .res to hold the .wav's, then exporting them. With the .wav's, its a HUGE game. like 196MB.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
To avoid the overall size just check if a file exists
Code:
Private Sub Form_Load()
Dim MyWav, wavFilepath, wavNetpath
MyWav = "mysound.wav"
wavFilepath = "??\???\????\"
wavNetpath = "??/???/????/"
If Not FileExists(wavFilepath & MyWav) Then download (wavNetpath & MyWav)
The .res can be 0MBs.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
No. You don't understand. I don't want them to have to download something. I want to use the .mp3, for everything to be already there. I wanted to use the .mp3 to cut the size of the download for it. =S
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Hi Gamemaster1494 :wave:
Quote:
Originally Posted by
Gamemaster1494
No. You don't understand.
Yip I understand, I understood from the get go.
The next big trend, Cloud Computing is Internet-based computing, whereby shared resources, software, and information are provided to computers and other devices on demand
Quote:
Originally Posted by
Gamemaster1494
I wanted to use the .mp3 to cut the size of the download for it. =S
Good idear
Quote:
Originally Posted by
Gamemaster1494
I don't want them to have to download something. I want to use the .mp3, for everything to be already there.
They have to download something, your app, and the .mp3/.wav in the app,
then your app makes anther copy, so now you have two copy's on disk.
Therefor if there is no .mp3/.wav in the app it would cut the size of the download, and the copy's on disk to.
Quote:
Originally Posted by
Gamemaster1494
Any ideas?
so.. yeah. plz help. i need this help so bad!
Code:
Private Sub Form_Load()
Dim Mymp3, mp3Filepath, mp3Netpath
Mymp3 = "mysound.mp3"
mp3Filepath = "??\???\????\"
mp3Netpath = "??/???/????/"
If Not FileExists(mp3Filepath & Mymp3) Then download (mp3Netpath & Mymp3)
Just an idea. ;)
Regards 5ms.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Okay. Another question then 5ms?. If i download it, can i download a .zip file? and can the mcisendstring thing play sounds from a .zip file?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Yip.
Yip.
Mmmm....No. ???????????
If you download a .zip, just unzip.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Yeah, i know that. im just wondering if it could do that. I'll think bout it. =)
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Manual repeat: Since you know the length of the tracks. Why not just store the length of each track? Then you can call "play" again after the duration(see post #4 or #7).
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Yeah. I have done that, but, it still had a delay. What if i put that code in a .dll? Would it go faster?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Quote:
Originally Posted by
Gamemaster1494
Yeah. I have done that, but, it still had a delay. What if i put that code in a .dll? Would it go faster?
Did you actually check the difference between say, Timer, or GetTickCount(good, accurate enough for this)? Or did you iterate a 'static' variable in a timer(bad, not accurate enough)?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
...Static.... xD um. How would i try to do that first one?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Create a 'static' variable(or private, or a property), but instead of iterating it on a timer, you add the length of the track when the track plays(like sVariable = Timer + length_of_track). Then you simply check: If Timer >= sVariable Then PlayNextSong.
Timer is built in to VB, and is accurate to the nearest hundredth second.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Quote:
Originally Posted by
Gamemaster1494
I need something that can loop perfectly like sndPlaySound does, but i also need something that can play .mp3 files... I dont want to have to use a control though. Any ideas?
If i have to use a control(like the ones in the tools...), then let me know.
The problem is that the .wav files are just WAY to big. I put them into a .res, and it makes the project HUGE. So, i want to try .mp3. Tried it with sndPlaySound(ik u cant use 'em. Just foolin around) and of course didnt work.... so.. yeah. plz help. i need this help so bad!
the size problem also can be solved.
you can zip your files, then insert them to the res file,
and on run time, unzip them.
you can easily build the zip and unzip functions your self,
using for example zlib.dll
or use third party zip/unzip like 7-zip for example.
another simpler solution is to insert the files to the res, as they are,
and at the end, zip the big exe file, with upx, it will get much smaller,
as if you packed the files with zip utility.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Are you sure your MP3 doesn't either have some blank lead-in or lead-out as part of the file? Using the mciSendString with repeat as part of the play command there should be no delay between the when the file ends and when the file starts again.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
I am positive MartT because i edited them with Audacity. No blank lead-in's or outs.
@FireXTol: I'm not certain what you are saying, but are you saying, to have a timer add to a variable, then if the variable is longer than the length of the track, start it over?
-
1 Attachment(s)
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
There must be more to your file than you think. Attached is a quick sample project that shows using repeat in the play command for mciSendString will play without a pause. Excuse the choice of mp3 but it was the first small file I found that didn't have a lead in and out to demonstrate with.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
MarkT. I have a feeling that due to the amount of code that i have in a different timer, that, it delays it to know when to loop. Because on my only timer, it has 1445 lines of code in it. Some of them are Calling a function.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Also MarkT, there is a problem with your .zip. Says can't find project or library. and highlights strFile = IIf(Right(App.Path, 1) = "\", "Duck.mp3", "\Duck.mp3")
the Right in it is what it highlights.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
You have other problems if VB6 does not recognize the Right function. To get past it in this example try replacing these 2 lines
Code:
strFile = IIf(Right(App.Path, 1) = "\", "Duck.mp3", "\Duck.mp3")
strFile = App.Path & strFile
with
Code:
strFile = App.Path & "\Duck.mp3"
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Would it be because you have 2 II in IIf?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
No, IIf is a function. About the only place I have found I like to use it is in this example where you are testing app.path. In this case I know that app.path will not end with a \ so we can just hardcode it here.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
It recognizes the Right function because i lowercased it, and went away from that code and it automaticly uppercased it..... Hum... werid. Now it is highlighting Chr and saying the same thing.... wth is wrong with my vb!?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
You have something wierd going on. The Chr function is a common one. To get past this one remove the Length and Position functions in the module since they aren't being used.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Hold on. Im going to restart my computer. It has been on for a while. Maybe that's the case. Idk.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Still not working. This is super weird.... Any idea y this would be happening? It doesn't even recognize Trim().....
-
1 Attachment(s)
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Attached is the stripped down example that addresses all the error you have seen. Let me know if it runs.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Hold on... I opened up References, and it is saying:
MISSING: Micorsoft Fax Service Extended COM Type Library
MISSING: faxcom 1.0 library types
IS that why it is not working!?
-
1 Attachment(s)
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Remove those references. Do you have these four selected.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Yes i do. I was able to find thoes 2 .dll's that caused it to say Missing, and it fixed it. =D
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
You don't need those DLLs referenced. That was something I had been working on earlier and forgot to exclude them before I zipped the project.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Hum...... It works with your sound, but not with my .mp3 music. =(
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Do you want to post a copy of the file?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
werid... because when i attached them, it worked with Right, and Chr....
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
oh. nvm. got it to work. xD now i just have to try it with my game.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
what does
If InStr(MpegAudio, " ") > 0 Then
MpegAudio = Chr(34) & MpegAudio & Chr(34)
End If
do? does it clip spaces on the end of the actual .mp3 file? or just the name?
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
That wraps the filename in double quotes if the filename contains spaces. It doesn't do any trimming.
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
Okay. just making sure. =)
-
Re: Is there something that acts and loops like sndPlaySOund, but can play .mp3 files
WOW! It works! I am surprised! I looked at some of my music files with Audacity again, and it looks like there was some things at the end that were silent. And, what i was trying to do before was play it, then check if it was done playing, then play it again. XD I didn't know there was a repeat function. Thanks MarkT! You were a real help. =)