Skip to content

Commit

Permalink
Implement generic SetVolume
Browse files Browse the repository at this point in the history
Should probably be optimized further as it is ran very often
  • Loading branch information
Python1320 authored Dec 2, 2024
1 parent 6516b4b commit b7b592e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lua/mediaplayer/services/browser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ SERVICE.Id = "browser"
SERVICE.Abstract = true

if CLIENT then
local JS_SetVolume = [[(function() {
function setvol(elem) {
elem.volume=%s;
}
var collection = document.getElementsByTagName("audio");
for (let i = 0; i < collection.length; i++) {
setvol(collection[i]);
}
collection = document.getElementsByTagName("video");
for (let i = 0; i < collection.length; i++) {
setvol(collection[i]);
}
})();]]

function SERVICE:GetBrowser()
return self.Browser
Expand All @@ -30,6 +45,9 @@ if CLIENT then

function SERVICE:SetVolume( volume )
-- Implement this in a child service
local vol = (volume or MediaPlayer.Volume())
local js = (JS_SetVolume):format( vol )
self.Browser:RunJavascript(js)
end

function SERVICE:Volume( volume )
Expand Down

0 comments on commit b7b592e

Please sign in to comment.