Skip to content

New extension: Pause specific audio channels when game is out of focus #1444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions extensions/community/PauseSoundNotFocus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"author": "",
"category": "Audio",
"extensionNamespace": "",
"fullName": "Pause specific sound channels when game is out of focus",
"helpPath": "",
"iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMy4wLjMsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iSWNvbnMiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgMzIgMzIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDMyIDMyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPg0KCS5zdDB7ZmlsbDpub25lO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoyO3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDtzdHJva2UtbWl0ZXJsaW1pdDoxMDt9DQo8L3N0eWxlPg0KPGc+DQoJPHBhdGggZD0iTTI5LDMwYy0wLjMsMC0wLjUtMC4xLTAuNy0wLjNsLTI2LTI2Yy0wLjQtMC40LTAuNC0xLDAtMS40czEtMC40LDEuNCwwbDI2LDI2YzAuNCwwLjQsMC40LDEsMCwxLjQNCgkJQzI5LjUsMjkuOSwyOS4zLDMwLDI5LDMweiIvPg0KPC9nPg0KPGc+DQoJPHBhdGggZD0iTTI3LDI4LjRWM2MwLTAuNC0wLjItMC43LTAuNS0wLjljLTAuMy0wLjItMC43LTAuMi0xLDBMMTMuNyw5SDcuNkwyNywyOC40eiIvPg0KCTxwYXRoIGQ9Ik01LjIsOS40QzUuMSw5LjYsNSw5LjgsNSwxMHYxMmMwLDAuNiwwLjQsMSwxLDFoNy43bDExLjgsNi45YzAuMSwwLDAuMiwwLjEsMC4yLDAuMUw1LjIsOS40eiIvPg0KPC9nPg0KPC9zdmc+DQo=",
"name": "PauseSoundNotFocus",
"previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/Glyphster Pack/Master/SVG/Computers and Hardware/248d073b73586eee2fc2cfc41cafc0d7ae9bec9ad4f8f8125592c63fa64b3c0d_Computers and Hardware_speaker_audio_sound_off.svg",
"shortDescription": "Pause a specific sound channels when game is out of focus.",
"version": "1.0.0",
"description": [
"This extension gives you the ability to pause specific sound channels when the game is out of focus, either because you switch windows, open another tab in the browser, or for any other reason.",
"",
"When focus is regained, the specified sound channel(s) will resume playback."
],
"tags": [
"audio",
"focus",
"sound",
"channel",
"pause"
],
"authorIds": [
"B89d8DyliabZDfWwc6DEmWSS7wk2"
],
"dependencies": [],
"globalVariables": [],
"sceneVariables": [],
"eventsFunctions": [
{
"description": "Pauses a sound channel when game is not focused, it will resumes when the game regained focus.",
"fullName": "Pause a sound channel if game isn't focused",
"functionType": "Action",
"name": "PauseASoundChannel",
"sentence": "Pause sound on channel _PARAM1_ when game is not focused",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"var sound_manager = runtimeScene.getGame().getSoundManager();\r",
"\r",
"window.addEventListener('focus', function (event) {\r",
"sound_manager.getSoundOnChannel(eventsFunctionContext.getArgument(\"SoundOnChannel\")).play();\r",
"});\r",
"\r",
"window.addEventListener('blur', function (event) {\r",
"sound_manager.getSoundOnChannel(eventsFunctionContext.getArgument(\"SoundOnChannel\")).pause();\r",
"});"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": false
}
],
"parameters": [
{
"description": "Sound channel",
"name": "SoundOnChannel",
"supplementaryInformation": "sceneSound Channel",
"type": "expression"
}
],
"objectGroups": []
}
],
"eventsBasedBehaviors": [],
"eventsBasedObjects": []
}