3

How to pause all playing sounds (Windows media palyer or another palyer) to play a specific sound in my application and then return to play the previous paused sound.

That is, if you want a sound is being played on a sound player like windows media player, my program pause this sound to play a specific sound, and after finishing the specific sound to play back the sound was paused. Can someone help me?

My delphi version is 2010. Thanks.

Welisson Goldmann
  • 107
  • 1
  • 4
  • 14
  • 2
    Suppose you managed to pull this off and I do the same from my app while your app is playing its sound - what would happen then? Put another way: this is probably not possible. – 500 - Internal Server Error Jan 02 '13 at 21:04
  • Why shouldn't it be possible, @500? Certain smartphones can do it. I don't know whether Windows supports anything like it, but there's no inherent reason that such a feature couldn't exist. I can think of three ways it could work with multiple programs: A second program could either pause the first program, and then resume just that program when finished, leaving the first one to resume all other programs once *it's* finished; or a second program could be forced to wait for a "pause mutex" before playing; or a second program could just fail to play at all. – Rob Kennedy Jan 02 '13 at 21:49
  • Sorry my friends thought it was not something so hard for someone so experienced in programming. I just needed to pause the song playing on windows media player, play a sound in my app and then continue the song on windows media player to the point where she had paused. If anyone can help me I thank you in advance! – Welisson Goldmann Jan 02 '13 at 22:48
  • 1
    You only need to pause Windows Media Player? – David Heffernan Jan 02 '13 at 23:40
  • Yeah... Basically what I need is to pause the music on windows media player, to be able to play a sound in my application and then replay the song in windows media player from the point where it was paused. – Welisson Goldmann Jan 03 '13 at 01:36
  • +1 I think this is a great question and don't see why all the fuss, other than OP asking for someone to basically "Share da codez" – Jerry Dodge Jan 03 '13 at 02:50
  • I'm assuming this shall also include things such as web browsers streaming audio, etc. I've asked a similar (but not duplicate) question: http://stackoverflow.com/questions/12126287/how-to-mute-the-sound-of-my-application – Jerry Dodge Jan 03 '13 at 02:53
  • 1
    Doesn't Skype also do this during an incoming call? I also heard a rumor that Skype was built in Delphi... – Jerry Dodge Jan 03 '13 at 02:55
  • 2
    How annoying if you manage to pull this off. Don't install your software on any machine that I work on. Thanks :) – Wouter van Nifterick Jan 03 '13 at 03:12
  • @WoutervanNifterick: I agree wholeheartedly, possibly with the exception of Skype. Even then I'd prefer the volume would be toned down instead of the replay being paused. After all, I may be listening to a radio station. – Marjan Venema Jan 03 '13 at 06:44
  • Good morning people, not necessarily pause the sound in wmp, mitigate would be enough, since the message of my application could be heard clearly, because it is important notices. Can anyone help me? – Welisson Goldmann Jan 03 '13 at 11:25
  • No one? Look if this can help me help =): I can do what I'm saying using winamp api, I can also do this in wndows vista + + using "setvolumeapp." However I need to do it with windows media player. – Welisson Goldmann Jan 03 '13 at 12:33
  • 1
    Your question says you want to pause "a sound player like Windows Media Player," which means you wish to be able to pause *any* arbitrary sound player. In your comments, you seem to suggest you *only* need to handle Windows Media Player. That distinction is important. Please [edit] your question to clarify. – Rob Kennedy Jan 03 '13 at 15:29
  • That's right Mr. Rob Kennedy, I just need to pause (or volume down) the windows media player. And later replay paused. I believe it is using FindWindow or api, etc.. Can you help me? – Welisson Goldmann Jan 03 '13 at 17:10
  • Skype probably uses the default communication device, in which case it's the **system** that reduces the sounds of *console* and *multimedia* applications according to **user configuration** in sound cpl's *communications* tab. – Sertac Akyuz Jan 03 '13 at 17:18

2 Answers2

2

You did not specify which version of Windows you are targeting. It makes a big difference if you want to control audio per application.

In Windows 7, you can control the volume per application (well.. stream).

Applications that use ASIO cannot be controlled like this, but if you only care about Windows Media Player that shouldn't be a problem. Mixer

You can control the volume (or mute) of streams via the Core Audio API. IAudioEndpointVolume or ISimpleAudioVolume interfaces.

However, I would't recommend messing with mixer volumes.

Windows has a mechanism built in that does what you want. It's called ducking or stream attenuation, which is meant to lower/mute the volume of all non-communication audio streams when a "communication" stream starts.

In the Windows multimedia control panel (Mmsys.cpl) you can configure the default behavior via on the communications tab:

Settings

You'll have to find the default communication device, and play audio through that.

This unit here can help you to find it: http://code.google.com/p/mfpack-media-foundation/source/browse/trunk/MFPACK/CoreAudio/MMDeviceAPI/MMDeviceApi.pas

From here on I'm not 100% if ducking occurs automatically when you play audio or not. I didn't try it myself, but hopefully this guides you in the right direction. Let me know if you book any results.

ps: If I were you I'd look a bit deeper into mfpack, because it seems to be a useful library for this kind of stuff. I see that there are 3 comitters for that project (maxcmx, factoryx.code, and peter larson). I'm sure they can tell you how to accomplish your goal the right way.

Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122
0

Searching on google I found a windows xp application that does exactly what I need, it is called an IndieVolume per-application volume control (link here) for Windows XP. I'll test it and see how it works, in the worst case I have to do a workaround so you can do what I want. NO but if someone has a better idea, I'm always willing to listen, or rather read on ...

Welisson Goldmann
  • 107
  • 1
  • 4
  • 14