diff --git a/panda/src/grutil/htmlVideoTexture.cxx b/panda/src/grutil/htmlVideoTexture.cxx index cc083ea225..c5182f141d 100644 --- a/panda/src/grutil/htmlVideoTexture.cxx +++ b/panda/src/grutil/htmlVideoTexture.cxx @@ -229,6 +229,47 @@ is_playing() const { }, this); } +/** + * Returns true if the video own audio is muted. True by default. + */ +bool HTMLVideoTexture:: +is_muted() const { + return EM_ASM_INT({ + return window._htmlVideoData[$0].video.muted; + }, this); +} + +/** + * Sets whether the video's own audio is muted. + */ +void HTMLVideoTexture:: +set_muted(bool muted) { + EM_ASM({ + window._htmlVideoData[$0].video.muted = ($1 !== 0); + }, this, muted); +} + +/** + * Returns the audio volume of the video element, in the range 0.0 to 1.0. + */ +double HTMLVideoTexture:: +get_volume() const { + return EM_ASM_DOUBLE({ + return window._htmlVideoData[$0].video.volume; + }, this); +} + +/** + * Sets the audio volume in the range 0.0 to 1.0. Note that you must also + * unmute the audio using the muted property. + */ +void HTMLVideoTexture:: +set_volume(double volume) { + EM_ASM({ + window._htmlVideoData[$0].video.volume = $1; + }, this, volume); +} + /** * A factory function to make a new HTMLVideoTexture, used to pass to the * TexturePool. diff --git a/panda/src/grutil/htmlVideoTexture.h b/panda/src/grutil/htmlVideoTexture.h index 2e0c03f561..e8a1f6a023 100644 --- a/panda/src/grutil/htmlVideoTexture.h +++ b/panda/src/grutil/htmlVideoTexture.h @@ -25,6 +25,10 @@ * - No RAM access of video data is possible * - No explicit synchronization with audio * - No loop count + * + * Unlike MovieTexture, this has an additional "muted" attribute which is true + * by default but can be set to false in order to play the video's audio via + * the browser interface. The "volume" property can configure the volume. */ class EXPCL_PANDA_GRUTIL HTMLVideoTexture : public Texture { PUBLISHED: @@ -47,6 +51,12 @@ PUBLISHED: double get_play_rate() const; bool is_playing() const; +public: + bool is_muted() const; + void set_muted(bool muted); + double get_volume() const; + void set_volume(double volume); + PUBLISHED: MAKE_PROPERTY(video_length, get_video_length); MAKE_PROPERTY(video_width, get_video_width); @@ -57,6 +67,9 @@ PUBLISHED: MAKE_PROPERTY(play_rate, get_play_rate, set_play_rate); MAKE_PROPERTY(playing, is_playing); + MAKE_PROPERTY(muted, is_muted, set_muted); + MAKE_PROPERTY(volume, get_volume, set_volume); + public: static PT(Texture) make_texture();