-
Dec 7th, 2009, 06:05 PM
#1
Thread Starter
Lively Member
[RESOLVED] Media Player volume and mute controls.
I have been at it for a while and cannot get it to work...
Here is what I got so far:
Code:
Imports AxWMPLib
Imports WMPLib
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.Load
SplitContainer1.Panel1.Controls.Add(Player)
Player.close()
End Sub
Private Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long
Sub Play_BackgroundSoundFile()
If waveOutGetNumDevs() >= 1 Then
Else
MsgBox("Your system can't play sounds. There could be probelm with your sound card...", 0 + 64, "Music Player")
exit sub
End If
Dim tmp As String = ("C:\users\aladamsk\documents\user\MIDILibrary\")
Player.URL = Nothing
Player.settings.autoStart = False
Player.URL = IO.Path.Combine(tmp, "bach_musette_D major.mid")
AddHandler Player.PlayStateChange, AddressOf mp_PlayStateChange
End Sub
Private Sub mp_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent)
If e.newState = 8 Then
Player.URL = Nothing
End If
End Sub
Public Sub VolumeUp()
If Player.settings.volume < 100 Then
Player.settings.volume += 1
End If
End Sub
Public Sub VolumeDown()
If Player.settings.volume > 0 Then
Player.settings.volume -= 1
End If
End Sub
Public Sub Mute()
'toggle mute
Player.settings.mute = Not Player.settings.mute
End Sub
I call the Sub Play_BackgroundSoundFile()
by double clicking on a picture box. The Start/Stop/Pause buttons work just fine, however I can not get the volume and mute to work.
I can physicaly click on the mute button and move the volume bar,
but I have no control over the music volume and mute function...
Obviously I am missing something. Could someone help me please ?
Last edited by adamarek; Dec 8th, 2009 at 09:22 PM.
-
Dec 7th, 2009, 11:51 PM
#2
Thread Starter
Lively Member
Re: Media Player volume and mute controls.
Anybody??? I am willing to try any suggestion....
-
Dec 8th, 2009, 12:42 AM
#3
Addicted Member
Re: Media Player volume and mute controls.
Are you looking for something similar?
Code:
Private Sub Mutemmute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mutemmute.Click
If player.settings.volume = player.settings.mute() Then
player.settings.volume = 20
Else
player.settings.volume = player.settings.mute()
End If
-
Dec 8th, 2009, 06:56 AM
#4
Thread Starter
Lively Member
Re: Media Player volume and mute controls.
Thank for replying to my post. However it does not work. I can see the volume slider move and the mute button being actuated but it has no effect on the sound volume or the mute function...
Last edited by adamarek; Dec 8th, 2009 at 09:22 PM.
-
Dec 8th, 2009, 09:20 PM
#5
Thread Starter
Lively Member
Re: Media Player volume and mute controls.
This is my last attempt finding a solution...
Anybody ??
-
Dec 11th, 2009, 09:18 PM
#6
Thread Starter
Lively Member
Re: Media Player volume and mute controls.
This is not exactly what I wanted but it will have to do for now..
In the following code, I am controling mute and the system master volume instead of my app.
1. Add button to media player.
a) add back ground image (speaker) to the button,
b) add ToolTip = "Mute"
2. Add track bar to media player.
a) set track bar value to 100
b) set min to 0, max to 100
The Code:
Code:
Imports AxWMPLib
Imports WMPLib
Imports System.Runtime.InteropServices ' add this line
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.Load
SplitContainer1.Panel1.Controls.Add(Player)
Player.close()
End Sub
Private Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long
Const WM_APPCOMMAND As UInteger = &H319 ' add those lines
Const APPCOMMAND_VOLUME_UP As UInteger = &HA
Const APPCOMMAND_VOLUME_DOWN As UInteger = &H9
Const APPCOMMAND_VOLUME_MUTE As UInteger = &H8
Sub Play_BackgroundSoundFile()
If waveOutGetNumDevs() >= 1 Then
Else
MsgBox("Your system can't play sounds. There could be probelm with your sound card...", 0 + 64, "Music Player")
exit sub
End If
Dim tmp As String = ("C:\users\aladamsk\documents\user\MIDILibrary\")
Player.URL = Nothing
Player.settings.autoStart = False
Player.URL = IO.Path.Combine(tmp, "bach_musette_D major.mid")
AddHandler Player.PlayStateChange, AddressOf mp_PlayStateChange
End Sub
Private Sub mp_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent)
If e.newState = 8 Then
Player.URL = Nothing
End If
End Sub
Private Sub ButtonMutePlayer_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button46.Click
'mute & restore
SendMessage(Me.Handle, WM_APPCOMMAND, &H200EB0, APPCOMMAND_VOLUME_MUTE * &H10000)
End Sub
Dim tbValue As Integer
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
' up and down volume
If TrackBar1.Value < tbValue Then
SendMessage(Me.Handle, WM_APPCOMMAND, &H30292, APPCOMMAND_VOLUME_UP * &H10000)
ElseIf TrackBar1.Value > tbValue Then
SendMessage(Me.Handle, WM_APPCOMMAND, &H30292, APPCOMMAND_VOLUME_DOWN * &H10000)
End If
tbValue = TrackBar1.Value
End Sub
End Class
Mute button mutes the system sound, so remember to restor the sound befor exiting your
application. You can do this in form exit event, otherwise all applications will be muted.
I am sure this is not the best solution, and I hope someone will improve on that.
I guess it is partialy resolved ...
-
Jun 11th, 2010, 01:18 PM
#7
Lively Member
Re: [RESOLVED] Media Player volume and mute controls.
I am getting an error "Name SendMessage is not declared." I am, however, using VB 2005.
Anyone who does not wonder, is either omnipotent or a fool.
Amerigoware <<<My Projects
-
Jun 11th, 2010, 03:57 PM
#8
Thread Starter
Lively Member
Re: [RESOLVED] Media Player volume and mute controls.
I do not know about 2005, but try this and see if it works:
Public Class Form1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
' Rest of your code here.....
End Class
-
Jun 12th, 2010, 01:09 AM
#9
Lively Member
Re: [RESOLVED] Media Player volume and mute controls.
You're awesome! Thank you all very much!
Anyone who does not wonder, is either omnipotent or a fool.
Amerigoware <<<My Projects
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
|