Results 1 to 9 of 9

Thread: [RESOLVED] Media Player volume and mute controls.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    98

    Resolved [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.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    98

    Re: Media Player volume and mute controls.

    Anybody??? I am willing to try any suggestion....

  3. #3
    Addicted Member
    Join Date
    Jul 2009
    Posts
    140

    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    98

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    98

    Re: Media Player volume and mute controls.

    This is my last attempt finding a solution...
    Anybody ??

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    98

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

  7. #7
    Lively Member Amerigo's Avatar
    Join Date
    Dec 2008
    Location
    PSR B1620-26 c-1
    Posts
    126

    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

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    98

    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

  9. #9
    Lively Member Amerigo's Avatar
    Join Date
    Dec 2008
    Location
    PSR B1620-26 c-1
    Posts
    126

    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
  •  



Click Here to Expand Forum to Full Width