Javascript set Boolean attribute

Just starting out? Need help? Post your questions and find answers here.
Evil1
User
User
Posts: 43
Joined: Fri Jul 15, 2016 8:55 pm

Javascript set Boolean attribute

Post by Evil1 »

Hi all, wondering if anyone can advise/help with an issue I have setting a Boolean option via Javascript.

Basically I have embedded Mediaplayer via a webgadget and I am attempting to use Javascript to activate controls.

The following controls work fine using

Code: Select all

SetGadgetText(0, "JavaScript:" + C$(x)"+";")

C$(1)=document.getElementById('Player').controls.stop()
C$(2)=document.getElementById('Player').controls.play()
C$(3)="var vid = 'http://stream/live/camera1.ts'"+";"
C$(4)="document.getElementById('Player').URL = vid"+";"
I have even managed to change the stream using e.g. the following :-

Code: Select all

SetGadgetText(0, "JavaScript:" + C$(3) + " JavaScript:"+C$(4)+ "JavaScript:"+C$(2))
But when it comes to toggling mute, I cannot for the life of me get it to work :-

MSDN states the following :-
============================================
Syntax

player.settings.mute
Possible Values

This property is a read/write Boolean.
Value Description
true Audio is muted.
false Default. Audio is not muted

==========MS scripting example================

<!-- Create an HTML CHECKBOX control. -->
<INPUT TYPE = "CHECKBOX" ID = MUTE
onClick = "
/* Use the CHECKBOX state to set
the mute property. */
Player.settings.mute = MUTE.checked;
">
===========================================

I have tried numerous permutations and am at a total loss e.g.

Code: Select all

SetGadgetText(0,"JavaScript:" + "document.getElementById('Player').settings.mute = true"+";")
I tried messing around with Element.setAttribute(name, value); too, but really do not have a clue.

There must be something simple I am missing, it doesn't help that I have never used Java/Javascript previously.

*The above appears to be returning the state of settings.mute and not setting it :-(

Thanks for looking.
Evil1
User
User
Posts: 43
Joined: Fri Jul 15, 2016 8:55 pm

Re: Javascript set Boolean attribute

Post by Evil1 »

I have managed to make some progress :-

If I append JavaScript:"+"Player.controls.play()"+";" to the following, it works!, well sort of, it does mute as intended but the stream restarts ( a slight pause and then resumes) as I have sent the play command again. (I don't know why that "helps", why it is needed and if I can send something else that doesn't cause the stream to restart. Any ideas?

Code: Select all

SetGadgetText(0,"JavaScript:" + "document.getElementById('Player').settings.mute = true"+";")
If I don't send Player.controls.play() after the above I get a blank page with a "㘰" character.
Evil1
User
User
Posts: 43
Joined: Fri Jul 15, 2016 8:55 pm

Re: Javascript set Boolean attribute

Post by Evil1 »

Figured this out, I tried to do shortcuts ( I am lazy like that :-))

Ended up looking at code written by JHPJHP, Freak and NetMaestro.

Thanks guys, you rock :-)
Post Reply