![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Help using this function
Can someone please help me write the code to increase / decrease the volume of the file being played. The function has already been declared i just don't know how to use the function.
Please help me i've tried everything and i think i'm just making a stupid mistake. Well anyways i have the playsong and stopsong code working so it's just the volume which i'm stuck on the file is in the attachement. Any help would be greatly appreciated. I hard coded the file to be played at "c:\song1.mp3" for you conveinience so if you have a .mp3 just name it song1.mp3 and play it in the root of your c:\ drive. Once you press start the song will comence. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
is anyone please able to help me?? i'm really stuck.. and help would be greatly appreciate.
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Alright i'll make it as easy as possible for you guys to help me. Here's the class module
'////////////////////////////////// Private strAlias As String ' Used internally to give an alias name ' to the multimedia resource Private strFileName As String ' Holds the filename internally Private sngLength As Single ' Holds the length of the filename ' internally Private sngPosition As Single ' Holds the current position internally Private strStatus As String ' Holds the current status as a string Private blnWait As Boolean ' Determines if VB should wait until ' play is complete before returning. Private lngVolume As Long ' Holds the current volume ' ----------------- API DECLARATIONS ----------------------- 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 Public Sub mmOpen(ByVal strTheFile As String) Dim lngReturn As Long ' Hold the value returned by the mciSendString command Dim strType As String ' Holds the file type ' Open the specified multimedia file and close any others that may be open If strAlias <> "" Then mmClose End If ' Determine the type of file Select Case UCase(Right(strTheFile, 4)) Case ".WAV" strType = "Waveaudio" Case ".AVI" strType = "AviVideo" Case ".MID" strType = "Sequencer" Case ".MP3" strType = "MPEGVideo" Case "MPEG", ".MPG" strType = "MPEGVideo" Case Else ' If the extension is not reconized then exit the sub Exit Sub End Select strAlias = Right(strTheFile, 3) & Minute(Now) ' If there are spaces in the file name the enclose it in quotess. If InStr(strTheFile, " ") Then strTheFile = Chr(34) & strTheFile & Chr(34) End If ' open the file If strType = "Other" Then lngReturn = mciSendString("Open " & strTheFile & " ALIAS " & strAlias _ & " WAIT", "", 0, 0) Else lngReturn = mciSendString("Open " & strTheFile & " ALIAS " & strAlias _ & " Type " & strType & " WAIT", "", 0, 0) End If End Sub Public Sub mmClose() ' Close the currently open multimedia file Dim lngReturn As Long ' Hold the value returned by the mciSendString command ' If there is no file open then exit the sub If strAlias = "" Then Exit Sub End If lngReturn = mciSendString("Close " & strAlias, "", 0, 0) strAlias = "" strFileName = "" End Sub Public Sub mmPause() ' Pause playback of the file Dim lngReturn As Long ' Hold the value returned by the mciSendString command ' If there is no file open then exit the sub If strAlias = "" Then Exit Sub End If lngReturn = mciSendString("Pause " & strAlias, "", 0, 0) End Sub Public Sub mmPlay() ' Plays the currently open file from the current position Dim lngReturn As Long ' Hold the value returned by the mciSendString command ' If there is no file open then exit the sub If strAlias = "" Then Exit Sub End If If blnWait Then lngReturn = mciSendString("Play " & strAlias & " wait", "", 0, 0) Else lngReturn = mciSendString("Play " & strAlias, "", 0, 0) End If End Sub Public Sub mmStop() ' Stop using a file totally. Running or not. Dim lngReturn As Long ' Hold the value returned by the mciSendString command ' If there is no file open then exit the sub If strAlias = "" Then Exit Sub End If lngReturn = mciSendString("Stop " & strAlias, "", 0, 0) End Sub Public Sub mmSeek(ByVal sngPosition As Single) ' Seek a specific position within the file Dim lngReturn As Long ' Hold the value returned by the mciSendString function lngReturn = mciSendString("Seek " & strAlias & " to " & sngPosition, "", 0, 0) End Sub Public Property Get FileName() As String ' Returns the object FileName Property FileName = strFileName End Property Public Property Let FileName(ByVal New_FileName As String) ' Sets the objects FileName property. This also implies ' that you also want to open the file so control is passed ' to the mmOpen method strFileName = New_FileName mmOpen New_FileName End Property Public Property Get Wait() As Boolean ' Returns the objects wait property Wait = blnWait End Property Public Property Let Wait(ByVal New_Wait As Boolean) ' Sets the value of the object Wait property blnWait = New_Wait End Property Public Property Get Length() As Single ' Returns the length of the currently open multimedia file Dim lngReturn As Long ' Hold the value returned by the mciSendString Dim intLength As Integer Dim strLength As String * 255 ' Holds the returned length from the mci ' status call ' If there is no open file then return 0 If strAlias = "" Then Length = 0 Exit Property End If lngReturn = mciSendString("Status " & strAlias & " length", strLength, 255, 0) intLength = InStr(strLength, Chr(0)) Length = Val(Left(strLength, intLength - 1)) End Property Public Property Get Position() As Single ' Returns the current position in the file Dim lngReturn As Long ' Hold the value returned by the mciSendString Dim intLength As Integer Dim strPosition As String * 255 ' Holds the returned length from the mci ' status call ' Exit the property if there is no file open If strAlias = "" Then Exit Property End If ' Get the position and return lngReturn = mciSendString("Status " & strAlias & " position", strPosition, 255, 0) intLength = InStr(strPosition, Chr(0)) Position = Val(Left(strPosition, intLength - 1)) End Property Public Property Let Position(ByVal New_Position As Single) ' Set the position property by seeking sngPosition = New_Position mmSeek New_Position End Property Public Property Get Status() As String ' Return the playback/record status of the current file Dim lngReturn As Long ' Hold the value returned by the mciSendString Dim intLength As Integer Dim strStatus As String * 255 ' Holds the returned length from the mci ' status call ' Exit the property if there is no file open If strAlias = "" Then Exit Property End If lngReturn = mciSendString("Status " & strAlias & " mode", strStatus, 255, 0) intLength = InStr(strStatus, Chr(0)) Status = Left(strStatus, intLength - 1) End Property Public Property Let Volume(ByVal New_Volume As Long) ' Sets the play back volume Dim lngReturn As Long ' Hold the value returned by the mciSendString ' Exit the property if there is no file open If strAlias = "" Then Exit Property End If ' Exit the property if the volume is out of range If New_Volume < 0 Or New_Volume > 100 Then Exit Property End If ' Set the volume lngVolume = New_Volume * 10 lngReturn = mciSendString("setaudio " & strAlias & " Volume to " & lngVolume, "", 0, 0&) End Property Public Property Get Volume() As Integer Volume = lngVolume End Property '/// here's frmMain ///////////////////////////////////////// Private Sub cmdPlay_Click() PlaySong "C:\song1.mp3" cmdPlay.Enabled = False cmdStop.Enabled = True End Sub Private Sub cmdStop_Click() objMM.mmStop cmdPlay.Enabled = True cmdStop.Enabled = False End Sub '////////////// Now what do i write to access the volume property? |
|
|
|
|
|
#4 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Quote:
Option Explicit Dim objMM As MMedia 'Declare the object Private Sub PlaySong(ByVal Song As String) 'Check if a media object has been created 'Create if it hasn't been If objMM Is Nothing Then Set objMM = New MMedia End If 'You need to open the file before it can be played objMM.mmOpen Song 'Now you can play it objMM.mmPlay End Sub Private Sub cmdPlay_Click() PlaySong "C:\song1.mp3" cmdPlay.Enabled = False cmdStop.Enabled = True End Sub Private Sub cmdStop_Click() objMM.mmStop cmdPlay.Enabled = True cmdStop.Enabled = False End Sub |
|
|
|
|
|
|
#5 |
|
Programmer
|
You may want to put it into code tags... or no one is going to help you.
Either way... I don't know enough to help you anyways ![]() |
|
|
|
|
|
#6 | |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#7 |
|
Sexy Programmer
|
why is that Polyphemus?
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#8 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
Here are some changes which make it work:
1. You don't initialise lngVolume - so it ends up with an initial value of 0 - that means that when you first click the volume up or down you get no sound. 2. You multiply the value of lngVolume by 10 in the setter - this would quickly lead to the volume being way out of range. Here is what I ended up with (note the * 10 is now just in the bit sent to mci) Public Property Volume() As Short
Get
Volume = lngVolume
End Get
Set(ByVal Value As Short)
' Sets the play back volume
Dim lngReturn As Integer ' Hold the value returned by the mciSendString
' Exit the property if there is no file open
If strAlias = "" Then
Exit Property
End If
' Exit the property if the volume is out of range
If Value < 0 Or Value > 100 Then
Exit Property
End If
' Set the volume
lngVolume = Value
lngReturn = mciSendString("setaudio " & strAlias & " Volume to " & (lngVolume * 10), "", 0, 0)
End Set
End Property3. The onlclick volume code didn't do anything besides print. I changed it to: Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
objMM.Volume = objMM.Volume + 10
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
objMM.Volume = objMM.Volume - 10
End SubNote that I don't have VB6 so this has all been upgraded to VB 2005. I think the code should still work. 4. Always use code tags! Last edited by The Dark; Feb 27th, 2006 at 12:41 AM. Reason: Fixing up tabs |
|
|
|
|
|
#9 | |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 218
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#10 |
|
Sexy Programmer
|
w0w, maybe I should have thought of that....
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|