[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

MCI or WAFEFORM volume change effect global windows volume settings

Posted on 2002-06-27
9
Medium Priority
?
646 Views
Last Modified: 2007-12-19
Hi All,
I got a big problem:
When I play back wave file and change volume,the change will affect windows global volume settings (I mean you can see you change in windows volume control in control pannel).
I have tried:
1.MCI. mciSendCommand("setaudio thename valume to ....  When opened as avivideo
2.WaveForm. waveoutSetVolume()
Both of them working the same way.
Does someone have any idea how can I change volume for currently open waveaudio file only?

I prefer to open the wave file as waveaudio using mci.
0
Comment
Question by:soferstam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 2

Expert Comment

by:dmarco
ID: 7117492
Declare this API function in a standard module:

Public Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long

Public dvcid As Long ' these two variables will contain API function values
Public VolMedia As Long
--------------------------------------------------

Add a form to your project with a Command button (Command1) and a MCI control (MMC1), set the PlayEnabled,StopEnabled,PrevEnabled,NextEnabled properties to true and paste this code:

Dim FileSound as string

Private Sub Form_Load()

FileSound = "Mysound.wav" 'this is a sample wav file'

MMC1.Notify = False  'initialize MCI control
MMC1.Wait = True
MMC1.Shareable = False
MMC1.FileName = App.Path & "\" & FileSound 'open MCI control'
MMC1.Command = "Open"

dvcid = MMC1.DeviceID

InputString = InputBox("Enter a value from 0 to 65535", "MCI Volume setting")

VolMedia = Val(InputString)
End Sub

Private Sub MMC1_PlayClick(Cancel As Integer) 'Start playing wavesound
Call waveOutSetVolume(ByVal dvcid, VolMedia)  'adjust volume without modifiyng win control panel'

End Sub

Private Sub Command1_Click() 'This will reset the volume scale as before  starting the program'
VolMedia = &HFFFF
Call waveOutSetVolume(ByVal dvcid, VolMedia)

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
MMC1.Command = "Close" 'close your MCI control when you close the form'

End Sub

Notice that playing your wavesound file doesn't alter the volume control setting. However you must click command1 after playing sound, otherwise you will get an altered volume scale when you check your windows volume control.

It must be stressed that Volume settings are interpreted logarithmically. This means the perceived increase in volume is the same when increasing the volume level from 0x5000 to 0x6000 as it is from 0x4000 to 0x5000.

Hope this helps
0
 
LVL 1

Author Comment

by:soferstam
ID: 7117616
It's good to know,but I have a reason to use API calls only and not the MMC control.
I'm doing more or less the same:
Open file using mciSendCommand("open...
Play file using mciSendCommand("play...
Get Device ID using mciGetDeviceID("my alias name...
Change volume using waveOutSetVolume(ByVal dvcid, VolMedia)
The device id I'm passing correctly.But the volume change going to be for master volume....
0
 
LVL 2

Expert Comment

by:dmarco
ID: 7117628
>>But the volume change going to be for master volume...

What do you mean exactly ? Are you playing another file with a different device, that is affected by the waveOutSetVolume function ? Or do you get a change in the volume control level in the win control panel ?

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:soferstam
ID: 7117632
I mean you can see you change in windows volume control in control pannel
0
 
LVL 2

Expert Comment

by:dmarco
ID: 7117652
When I tested my code the SETTINGS of the volume control were unchanged ( the level of the bar when you double click on the icon in the tray bar). However I found that the max volume output of my PC was changed  and it was equal to the volume set by the waveOutSetVolume function.
Therefore, if you use the code in the command1 click event
before closing the MCI control, you can restore the normal max volume output leaving unchanged the win volume control settings.

Private Sub Command1_Click()
VolMedia = &HFFFF
Call waveOutSetVolume(ByVal dvcid, VolMedia)
End Sub

0
 
LVL 1

Author Comment

by:soferstam
ID: 7117673
Thanks.
I will test it on Monday.
I know that if you open 2 instanses of Windows Media Player and play two different files at the same time and change volume on one of them it is not going to effect another.This is what I'm trying to simulate.
0
 
LVL 2

Accepted Solution

by:
dmarco earned 1200 total points
ID: 7120626
Win Media Player uses DirectX to output wave sound.
If you want to change independently the volume settings of multiple running instances of your application , I believe you can't do it using MCI control. Probably you have to use DirectX (DirectSound) in your code: this way you can have direct access to the hardware.
If you are interested to add DirectSound to your app., let me know and I'll try to find some code for you.

However a workaround can be tried using MCI control. Add the following code to the previous I have posted:
 
   'Open a second MCI control (MMC2) in the form_load event'

FileSound2 = "Mysound2.wav" 'this is a file different from that played by MMC1
MMC2.Notify = False
MMC2.Wait = True
MMC2.Shareable = False

MMC2.FileName = App.Path & "\" & FileSound2
MMC2.Command = "Open"

   'Enter another volume setting for MMC2 control'

InputString = InputBox("Enter a value from 0 to 65535", "MCI2 Volume setting")
VolMedia2 = Val(InputString)

  'Add the following event driven routines'

Private Sub MMC1_LostFocus()
MMC1.Command = "Pause"
End Sub

Private Sub MMC2_LostFocus()
MMC2.Command = "Pause"
End Sub

Private Sub MMC2_PlayClick(Cancel As Integer)
Call waveOutSetVolume(dvcid, VolMedia2)
End Sub

Using this code you can play 2 (or more) wav files at different volume settings and when your application is closed, you can get the general Windows volume setting unchanged. Of course you can play the MCI controls one AFTER the other and NOT all at the same time. If you need this last option, I believe you need DirectSound help....
Don't forget the restore routine (Command1_Click button code), in order to reset the max volume output of Windows after closing your program.

Good luck!   Marco
0
 
LVL 1

Author Comment

by:soferstam
ID: 7122515
Thanks.
I'm not sure if I will go to DirectX.
If yes I will post another question during this week.
0
 
LVL 2

Expert Comment

by:dmarco
ID: 7123212
Glad I could help you.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question