Volume Function


#1

Ok so I’m trying to set the Volume in a Video Player. I can’t get it to work right.

I know the doc is at volume setter doc
And I know I need an array to hold the setting, but I’m still not getting it.
Can someone explain the doc syntax to me?

volume(v : number[]) : void;

So if I read is right “v” is the variable it has to be an arrayed number ( per doc 0-1)
I have

var v = [.5,.5];
and
n360videoplayer0.nodes.control.volume(v);

When I test it I get sound but no video.
The other part is the “:void;” at the end. I know it has something to do with no data returned, I think…
But if I added it I get an error.

Thanks,
Steve


#2

Hi Steve,

Hope you’re well.

The volume function is inherited from a Z.Video object, which means it must be called on an object of that type.

The variable you’re attempting to access through your code isn’t of this type so won’t run as expected.

The video you assign to a videoPlayer symbol is stored in its ‘show0’ script as a variable of type ‘Z.Video’ called ‘myvid’.

As this variable contains the keyword ‘export’, you can access it from within the parent symbol.

To change the volume of the video associated with that videoPlayer symbol your code would look something like this:

exampleVideoPlayer.nodes.show0.myvid.volume([1,1]);

Secondly, in the docs page, the ‘:void’ at the end of the function denotes that the function returns a value of type ‘void’, which is commonly used as the return type of functions that don’t return a value.

Hope this helps.

Thanks,
Seb


#3

hay @Seb, well I’m still not getting it.
First I’m running the 360 video player symbol.

I have a script of

const n360videoplayer0 = symbol.nodes.n360videoplayer0;

n360videoplayer0.nodes.show0.myvid.volume([.3,.3]);

n360videoplayer0.on(“video:finish”, () => {
n360videoplayer0.nodes.control.restart();
});

When I play it with out a volume code it works fine. but as soon as I add the volume code it
scans then has the zap icon with unlocking on the screen. after a second or two you can hear the audio from the video but no video just the zap icon with unlocking . And even thou I have a loop setup it only plays one time.

Steve


#4

Hey steve,

Have you checked what kind of outputs you get in the debug console on pc side? Usually when the unlocking symbol stays on screen it indicates that there’s a runtime error of some kind that hangs the experience. My guess would be it has something to do with trying to change the volume before the videoplayer symbol has been initialized / populated.

Just a guess, but maybe try:

n360videoplayer0.on("ready", () => {
    n360videoplayer0.nodes.show0.myvid.volume([.3,.3]);
});

Also, I noticed that the volume() functions don’t work on the windows zappar, but works fine on devices. Kind of expected though as the underlying code is not meant for adjusting pc volume. Just something to keep in mind when debugging!


#5

You know I didn’t even think of that. I’ll try it.

Thanks,
Steve