3 Replies - 6506 Views - Last Post: 19 March 2013 - 07:37 AM Rate Topic: -----

#1 emile2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-December 12

Controlling volume for current application only

Posted 18 March 2013 - 08:11 AM

Hello DIC,

I've got a VB.NET related question.
I want to create a program which is able to set the volume in the volume mixer for the program itself - so not the master volume.
Can anyone help me for this or give me any directions?

All help appreciated.

Thanks in advance!
Is This A Good Question/Topic? 0
  • +

Replies To: Controlling volume for current application only

#2 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 245
  • View blog
  • Posts: 796
  • Joined: 01-February 13

Re: Controlling volume for current application only

Posted 18 March 2013 - 10:11 AM

Hello emile2012,
How is your program playing sounds? Are you using (mciSendString) to play a (wav) file or are you using an (AxWindowsMediaPlayer) to play music or viseos ? A little more info on how and what you are playing may help. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#3 emile2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-December 12

Re: Controlling volume for current application only

Posted 19 March 2013 - 12:21 AM

View PostIronRazer, on 18 March 2013 - 10:11 AM, said:

Hello emile2012,
How is your program playing sounds? Are you using (mciSendString) to play a (wav) file or are you using an (AxWindowsMediaPlayer) to play music or viseos ? A little more info on how and what you are playing may help. :bigsmile:/>

Thanks for replying. It uses a (hidden) webbrowser to play music.
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 245
  • View blog
  • Posts: 796
  • Joined: 01-February 13

Re: Controlling volume for current application only

Posted 19 March 2013 - 07:37 AM

Hi emile2012,
As far as controlling the volume of what comes threw the WebBrowser i am not sure if you can control volume without setting the system volume which would set the volume of everything. However, if you are playing online radio stations you can use an (AxWindowsMediaPlayer) to do it. There is a tutorial HERE on this site that shows how. If you want it hidden then you can use a Trackbar to adjust the volume like this which will only effect your programs volume
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TrackBar1.Maximum = 100
        TrackBar1.TickFrequency = 10
    End Sub

    Private Sub TrackBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
        AxWindowsMediaPlayer1.settings.volume = TrackBar1.Value
    End Sub


You can also use it to play music files located on your computer. There is also the option of using DirectX to play music and adjust its volume. HERE is a short tutorial on doing it. You would need the DirectX SDK installed to use it. You can download the SDK from Microsoft . Here is how you could set it up to control the volume using a Trackbar
Imports Microsoft.DirectX
Imports Microsoft.DirectX.AudioVideoPlayback

Public Class Form1
    Dim Music As Audio = Nothing

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TrackBar_Volume.Maximum = 10000
        TrackBar_Volume.TickFrequency = 1000
    End Sub

    Private Sub Button_Play_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Play.Click
        Music = New Audio("c:\Test\musicfile.mp3", False)
        Music.Play()
        Music.Volume = (10000 - TrackBar_Volume.Value) * -1
    End Sub

    Private Sub Button_Stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Stop.Click
        Music.Stop()
        Music.Dispose()
        Music = Nothing
    End Sub

    Private Sub TrackBar_Volume_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar_Volume.ValueChanged
        ' 0 (maximum) to -10000 (which is silent)
        Music.Volume = (10000 - TrackBar_Volume.Value) * -1
    End Sub
End Class


Make sure you add a reference to Microsoft.DirectX and Microsoft.DirectX.AudioVideoPlayback by going to (Project / Add Reference) and then on the (.Net) tab add them. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1