Browser audio control - windows

If you use firefox (and I assume it works similarily with Chrome/Edge) or Spotify, and you press audio play/pause button, it pauses video/music you are listening to. When my headphones start running out of battery they pause audio for a moment, tell me battery is about to run out, and resume playing. Ergo, I assume there is a way to send "pause music" message, or sth similar.
So my question is: If I have an app (in this case unity game), is there a way in which I can send similar "pause" message to browsers/spotify?

Related

When a video starts on Cobalt 19, is there a callback that will alert me when video starts?

I need to handle the Play/Pause remote button which is sending the same code, I am able to toggle and send Play or Pause based on the previous key press, but I am trying to reset the toggle when video starts. For example, if video is paused, then the remote skips to the next track, the toggle is still in pause mode which would require the user to press play twice to get the next video to pause.
The source code is vast and I have been blindly searching for strings with no luck.
If you have only one physical key on a remote, send a kSbKeyMediaPlayPause key instead of trying to guess the state of a web app.

Reliably pause all playing media on Windows

I am setting up a plugin for KDE Connect where I pause any playing media as and when I get a call on my phone. For the Windows build of this plugin, I am currently using VK_MEDIA_PLAY_PAUSE. Is there some instruction(s) I can use to simply PAUSE or simply PLAY the media? That is, not a toggle, instruction(s) with "only one" of the two behaviours?
IF not, is there some other way I can reliably determine if there is any media playing on my system?
I have read Media Play/Pause Simulation . but a toggle is not reliable in my use case.
WM_APPCOMMAND has APPCOMMAND_MEDIA_PAUSE. Send it directly to a player if you know its HWND or send it to yourself and let DefWindowProc turn it into a shell hook event.

jPlayer play event is not firing when audio start playing automatically

I got a problem with jPlayer.
When the page loaded, the player plays automatically but it doesn't trigger "play" event.
Only when I click on pause button and click on play button again, the event is triggered.
Is that a bug of jPlayer?
hard to say since you don't mention which browser you are experiencing this in but my experience is that it is safer to rely on the 'playing' event rather than the 'play' event. Ideally the 'play' event is to be fired as soon as you call jPlayer('play') and 'playing' then is fired once the actual playback starts (i.e. after initial buffering etc). What I've seen this works fine in Safari but does not work in Chrome, in Chrome the two events are both fired when content starts to play.

How to determine which player it will start by sending a Virtual-Key VK_LAUNCH_MEDIA_SELECT

Under Win2K(or later), by sending a Virtual-Key VK_LAUNCH_MEDIA_SELECT, can start a player.
If more than one player software installed, how to determine which one it will start?
A sample VBS code:
Wscript.CreateObject("Wscript.Shell").Sendkeys chr(&h88b5)
http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
http://msdn.microsoft.com/zh-cn/library/dd375731
VK_LAUNCH_MEDIA_SELECT
0xB5
Select Media key
VK_LAUNCH_MEDIA_SELECT is actually received by the system and translated into a WM_APPCOMMAND with lParam as APPCOMMAND_LAUNCH_MEDIA_SELECT. So theoretically, any program implementing a handler for this could be launched. This page (albeit old) lists default applications which listen for WM_APPCOMMAND:
Internet Explorer
Windows Help
DVD Player
CD Player
Media Player
Volume Control system tray applet
Obviously, only a few of those are actually applicable for APPCOMMAND_LAUNCH_MEDIA_SELECT.
However, I don't know how the translation mechanism actually works. It appears not every application will receive the translated WM_APPCOMMAND message. On my keyboard, I tried pressing the button which sends VK_VOLUME_UP. The volume goes up as expected because it is handled by the volume control system tray applet. However, I opened an instance of notepad.exe and monitored its messages with Spy++. It did not receive any message even when it was in the foreground. Curiously, VK_MEDIA_PLAY_PAUSE is received through WM_APPCOMMAND if the play/pause button is pressed as long as notepad.exe had the focus. I would test with VK_LAUNCH_MEDIA_SELECT, but I'm not actually sure what button that corresponds to (or whether my keyboard has it).
Thanks, for Mike Kwan's reply.
Through testing a lot of settings a program associated with a variety of audio files.
Finalized, this will depend on the CDA (CD Audio) files associated with which program.
If you set the default association for the CDA (CD Audio) files to Notepad or Paint or any other program, it can still send the same virtual key to open the corresponding program.
The foreground window can do whatever it wants in response to the WM_APPCOMMAND message, if it does not handle the message then shell hooks (HSHELL_APPCOMMAND) gets to handle it, if no hooks handle the message then Windows checks the AppKey key in the registry. (You can use Process Monitor to find the number for a specific key-press)

AppleScript event listening

I'm wanting to make a AppleScript to give me the current track name playing on itunes. So far I have made it get the name and refresh after the song has played with duration of the song.
Delay Song_duration
What I'm getting a problem is if the user skips the song manually or changes the song; I can see the are events called "next track" and "previous track" but it seems you can't do stuff like:
if (next track) then
because it does the event in the brackets. What I'm wanting to know is if there is a way to listen for the event. I don't know much about AppleScript, just been looking online for answers.
The general gist of the script is I want to get the name of the track and artist instantly with as little CPU/Memory as possible or I would just do delay 1.
Basically you can't do it with applescript.
iTunes sends out a system wide notification whenever it's state changes called "com.apple.itunes.playerInfo". So you need to write in a language that can receive system notifications, objective-c for example. In that language you register for system notifications under the NSDistributedNotificationCenter. Once registered your program would run in the background, using little to no system resources, and then whenever something changes in iTunes your program would receive a notification and then you do something with iTunes.
Here's a link to a similar question and a couple solutions are posted.

Resources