-
Mar 25th, 2012, 02:23 PM
#1
Thread Starter
PowerPoster
Adjust Audio Volume
Is there any way to adjust audio volume directly using .net ?
I can only find C++ coding which, sadly means nothing to me.
I would like to be able to record the current Audio Volume setting, change it (up or down), play a *.wav file, then return it to it's original level.
Is this possible?
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Mar 25th, 2012, 04:01 PM
#2
Re: Adjust Audio Volume
Try to convert this VB6 example to VB.Net, maybe it work with you. http://support.microsoft.com/kb/118377
-
Mar 25th, 2012, 05:53 PM
#3
Thread Starter
PowerPoster
Re: Adjust Audio Volume
Originally Posted by 4x2y
Thanks for the suggestion 4x2y but, as it seems to me, the code in the VB6 example depends upon the presence of MMSYSTEM.DLL and it's just not anywhere in my PC.
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Mar 25th, 2012, 08:44 PM
#4
Banned
-
Mar 26th, 2012, 06:37 AM
#5
Re: Adjust Audio Volume
Originally Posted by moti barski
Thanks, the code at that link works great and can easily adapted to control the volume on a control click instead of control mouse move.
-
Mar 28th, 2012, 06:16 PM
#6
Thread Starter
PowerPoster
Re: Adjust Audio Volume
Originally Posted by moti barski
Yes, as 4x2y says 'can be easily adapted' and this works as far as it goes.
I ran this code by way of a simple trial and, using buttons to observe the results, I can move the Master Volume Control up and down with ease.
Code:
Imports System.Runtime.InteropServices
Public Class Form1
Private Const VolUp As Integer = &HA0000
Private Const VolDn As Integer = &H90000
Private Const MsgNo As Integer = &H319
Declare Function SendMessageW Lib "user32" (ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As IntPtr
Private Sub Form1_Load() Handles MyBase.Load
Button1.Text = "UP"
Button2.Text = "DOWN"
Button3.Text = "Close"
End Sub
Private Sub Button1_Click() Handles Button1.Click
SendMessageW(Me.Handle, MsgNo, Me.Handle, New IntPtr(VolUp))
End Sub
Private Sub Button2_Click() Handles Button2.Click
SendMessageW(Me.Handle, MsgNo, Me.Handle, New IntPtr(VolDn))
End Sub
Private Sub Button3_Click() Handles Button3.Click
End
End Sub
End Class
My problem is still that I can neither read the current volume level nor get any feedback to say that the action was successful or otherwise.
Either of these would allow me to adjust the volume and then return it to where it was...
This being my primary object, reading the current position would be the feedback of choice making for neater code.
I figure that reading the current position must be possible because evoking the ' Volume Mixer - Speakers' in most Windows versions does it.
Poppa.
Last edited by Poppa Mintin; Mar 28th, 2012 at 06:31 PM.
Along with the sunshine there has to be a little rain sometime.
-
Mar 30th, 2012, 06:25 PM
#7
Thread Starter
PowerPoster
Re: Adjust Audio Volume
Originally Posted by Poppa Mintin
My problem is still that I can neither read the current volume level nor get any feedback to say that the action was successful or otherwise.
Either of these would allow me to adjust the volume and then return it to where it was...
This being my primary object, reading the current position would be the feedback of choice making for neater code.
I figure that reading the current position must be possible because evoking the ' Volume Mixer - Speakers' in most Windows versions does it.
Still trying to find an answer to this question, I see that I'm only one of dozens, if not hundreds, asking the same question and that none of us are getting straight answers...
I also see the there are many sites offering to sell us the answer, but I'm not willing to use my pension just to discover that the question isn't actually answered.
There are sites that publish reams and reams of supposedly VB.NET code, none of which looks very much like usable code to me and wading through these listings trying to
find something that looks as though it might relate to the problem of reading the master volume setting is becoming very tedious.
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Mar 30th, 2012, 08:25 PM
#8
Fanatic Member
Re: Adjust Audio Volume
Controlling the sound is actually a very hard thing to do...and it got even more complicated in Windows Vista and up. I have never been able to find this type of stuff in .NET and I looked rather extensively for a project I was trying to do. I'm sure it's there, but it's not well-documented because of it's complexity. .NET doesn't have any managed code to handle volume. The place most likely for that to be found will be in that C++ code you came across.
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Mar 31st, 2012, 07:07 AM
#9
Thread Starter
PowerPoster
Re: Adjust Audio Volume
Originally Posted by Seraph
Controlling the sound is actually a very hard thing to do...and it got even more complicated in Windows Vista and up. I have never been able to find this type of stuff in .NET and I looked rather extensively for a project I was trying to do. I'm sure it's there, but it's not well-documented because of it's complexity. .NET doesn't have any managed code to handle volume. The place most likely for that to be found will be in that C++ code you came across.
Thanks for your comment, actually as you can see from my code above handling the master volume is quite straight forward, this being so I'd've thought just getting the setting would be fairly straight forward too.
Even some return from the function to confirm or deny that the operation was completed (not just sent but that a change was made) could be used for my purposes...
e.g. count the number of reductions required to reach zero... Do my stuff, then zero the volume and increase it the same number of times it originally took to get to zero ought to be a reasonable approximation...
A bit crude maybe but at least workable.
As it is, I may have to display a message at the close of my project to say that the master volume has been set to zero and that the user should set it back to where they want it... Now that is crude !
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Mar 31st, 2012, 07:34 AM
#10
Re: Adjust Audio Volume
Originally Posted by Poppa Mintin
Thanks for your comment, actually as you can see from my code above handling the master volume is quite straight forward, this being so I'd've thought just getting the setting would be fairly straight forward too.
Even some return from the function to confirm or deny that the operation was completed (not just sent but that a change was made) could be used for my purposes...
e.g. count the number of reductions required to reach zero... Do my stuff, then zero the volume and increase it the same number of times it originally took to get to zero ought to be a reasonable approximation...
A bit crude maybe but at least workable.
As it is, I may have to display a message at the close of my project to say that the master volume has been set to zero and that the user should set it back to where they want it... Now that is crude !
Poppa.
Hmmm.....
Your code has nothing to do with the mixer. Your code sends info like a remote controle:
http://msdn.microsoft.com/en-us/libr.../bb417079.aspx
What you like is interacting with the mixer. What Seraph mentioned is that MS changed a lot from Vista and up.
-
Mar 31st, 2012, 07:45 AM
#11
Fanatic Member
Re: Adjust Audio Volume
Yeah, it's pretty straightforward but that is coming from unmanaged code; that isn't a part of .NET
That was all the point i was making. That is pretty simple compared to other unmanaged things I've seen.
i wouldn't be surprised if what you need is also a part of that unmanaged code, but since it's hard to find documentation that exposes unmanaged code methods, I bet it will be hard to find any more than that. (as you seem to have already discovered...lol)
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Mar 31st, 2012, 04:25 PM
#12
Banned
Re: Adjust Audio Volume
@Poppa Mintin I think you're talking about a fast realtime vb.net 2010 speaker volume meter.
that and a usb microphone vb.net volume meter are the rarest of the rare of codes in vb.net and the fact they don't exist is just tragic.
maybe someday a genius will solve it and make them available to all of us and open the gateway to a new age of technology and stuff.
having said that, if you set the volume level then it is what you set it to, isn't it ?
-
Mar 31st, 2012, 04:45 PM
#13
Re: Adjust Audio Volume
If you call SendMessageW(Me.Handle, MsgNo, Me.Handle, New IntPtr(VolDn)) 50 times on form load, you will be assure that the volume is at 0%, then with a module level variable you can track the volume level. The main problem is that you will lost if the user change the volume outside your program.
-
Mar 31st, 2012, 06:38 PM
#14
Thread Starter
PowerPoster
Re: Adjust Audio Volume
Originally Posted by 4x2y
If you call SendMessageW(Me.Handle, MsgNo, Me.Handle, New IntPtr(VolDn)) 50 times on form load, you will be assure that the volume is at 0%, then with a module level variable you can track the volume level. The main problem is that you will lost if the user change the volume outside your program.
Actually I do also have the code to mute the output altogether, but is not what I want to do...
I want to be able to adjust the output volume to a sensible level for the .wav file I want to play,
And then return the volume back to where it was and that's the trick that's eluding me.
The .wav file is only a few seconds long (maybe 10 tops) so 'outside changes' are't likely to occur.
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Mar 31st, 2012, 06:46 PM
#15
Thread Starter
PowerPoster
Re: Adjust Audio Volume
Originally Posted by Seraph
Yeah, it's pretty straightforward but that is coming from unmanaged code; that isn't a part of .NET
Ah... I see. So now I have to find out more about 'unmanaged code', I wasn't aware that what I was doing wasn't .NET.
Thanks for the info Seraph and for a new line of research.
I may not get back to this thread for a while, I'm going to be away for nearly four weeks...
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Apr 1st, 2012, 03:56 AM
#16
Re: Adjust Audio Volume
I posted something about this:
http://www.vbforums.com/showthread.php?t=640269
Before Vista a mixer console was build by the capabilities of the soundcard.
So you could control the sound of a running program by an other program. Not just volume but also re-routing. You could record the sound that was produced by other apps.
Now a mixer is build dynamicly by the needs of a app, so that is the other way arround.
For a better explenation read the post I mentioned.
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
|