Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 24th, 2006, 10:04 PM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
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.
Attached Files
File Type: zip audio player.zip (4.1 KB, 29 views)
Eric the Red is offline   Reply With Quote
Old Feb 25th, 2006, 1:33 AM   #2
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
is anyone please able to help me?? i'm really stuck.. and help would be greatly appreciate.
Eric the Red is offline   Reply With Quote
Old Feb 26th, 2006, 3:08 PM   #3
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
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?
Eric the Red is offline   Reply With Quote
Old Feb 26th, 2006, 3:41 PM   #4
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Quote:
Originally Posted by Eric the Red
'/// 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?
Sorry here's the full frmMain. From the bottom of the last post.

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
Eric the Red is offline   Reply With Quote
Old Feb 26th, 2006, 3:59 PM   #5
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
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
MrMan9879 is offline   Reply With Quote
Old Feb 26th, 2006, 4:17 PM   #6
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by MrMan9879
Either way... I don't know enough to help you anyways
Even if I knew enough I still wouldn't help him.
Polyphemus_ is offline   Reply With Quote
Old Feb 26th, 2006, 10:21 PM   #7
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
why is that Polyphemus?
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Feb 27th, 2006, 12:39 AM   #8
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 825
Rep Power: 4 The Dark is on a distinguished road
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 Property

3. 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 Sub


Note 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
The Dark is offline   Reply With Quote
Old Feb 27th, 2006, 3:43 AM   #9
zorin
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 218
Rep Power: 4 zorin is on a distinguished road
Quote:
why is that Polyphemus?
Because he has posted 5 times since his original post, my guess is that he is "bumping" his post in the hope that someone will answer his question.
zorin is offline   Reply With Quote
Old Feb 27th, 2006, 7:06 AM   #10
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
w0w, maybe I should have thought of that....
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC