Skip to content
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

About double click on player #8946

Open
campones opened this issue Dec 22, 2024 · 6 comments
Open

About double click on player #8946

campones opened this issue Dec 22, 2024 · 6 comments
Labels
needs: triage This issue needs to be reviewed

Comments

@campones
Copy link

campones commented Dec 22, 2024

Description

Hello
I have been using vjs for like 10 years now.
During most of these years, there was no fonction to double click on the player to go full screen so someone helped me out with something like this

<script>var vid1 = videojs('live_player'); vid1.persistvolume({ namespace: "videojs-user-volume" }); vid1.on('dblclick', function() { vid1.requestFullscreen(); }); vid1.on('dblclick', function() { vid1.exitFullscreen(); });

Until very recently I discovered that this feature was now builtin and so the code unnecesarry . Great.

I also have this piece of code
vid1.on("play",function(e){console.log('Hls started!');setTimeout(function() {vid1.pause()}, 7200000); });

When you open a page with a vjs player, the console write "Hls started!" which is the expected behavior.
But it also does the same when you go full screen by double clicking, either using my old way, or the new one builtin in the player.
My point is it seems that double clicking the player reset the player state, like a sort of OFF ON .

You must think, , so what?
Well I m using a nice little plugin, that I actually never deployed because I thought it wasn't working properly. Actually it does but since double clicking reset the player state and the plugin being a timer that display a message to stop the video feed after a while depending on how long the video has been playing makes it unusable

https://github.com/TylerZubke/Videojs-AFK-Monitor

So now I m stuck with this because at the moment, it seems my only option is to disable the double click so the plugin works the way I want to. but I really wouldn't want that as double clicking a screen to go full is just so intuitive and expected behavior.

videojs("my-player", {
    userActions: {
        doubleClick: false
    }
});

I do not provide a test page as I don't feel it's necessary, this is more a discussion.

Reduced test case

https://stackoverflow.com/help/minimal-reproducible-example

Steps to reproduce

1.described in the post
2.
3.

Errors

No response

What version of Video.js are you using?

8.20

Video.js plugins used.

afk monitor

What browser(s) including version(s) does this occur with?

all

What OS(es) and version(s) does this occur with?

all

@campones campones added the needs: triage This issue needs to be reviewed label Dec 22, 2024
@campones
Copy link
Author

just adding that actually I had to insert this in the data-setup for it to work
data-setup='{"userActions": {"doubleClick": false }}'

as writing this after the player won't work. but anyway, this is not the issue for me

<script>var vid1 = videojs('yourplayer', { userActions: { doubleClick: false }});</script>

@mister-ben
Copy link
Contributor

If you have set up a player with data-setup, videojs(id) called later is a getter that only returns the already initialised player. A second argument is ignored, that is only used when first initialising a player.

The double-click does not "reset" the player. It calls the browser's fullscreen API, same as a click on the fullscreen button:

video.js/src/js/player.js

Lines 2015 to 2062 in 19ca3f2

handleTechDoubleClick_(event) {
if (!this.controls_) {
return;
}
// we do not want to toggle fullscreen state
// when double-clicking inside a control bar or a modal
const inAllowedEls = Array.prototype.some.call(
this.$$('.vjs-control-bar, .vjs-modal-dialog'),
el => el.contains(event.target)
);
if (!inAllowedEls) {
/*
* options.userActions.doubleClick
*
* If `undefined` or `true`, double-click toggles fullscreen if controls are present
* Set to `false` to disable double-click handling
* Set to a function to substitute an external double-click handler
*/
if (
this.options_ === undefined ||
this.options_.userActions === undefined ||
this.options_.userActions.doubleClick === undefined ||
this.options_.userActions.doubleClick !== false
) {
if (
this.options_ !== undefined &&
this.options_.userActions !== undefined &&
typeof this.options_.userActions.doubleClick === 'function'
) {
this.options_.userActions.doubleClick.call(this, event);
} else if (this.isInPictureInPicture() && !document.pictureInPictureElement) {
// Checking the presence of `window.documentPictureInPicture.window` complicates
// tests, checking `document.pictureInPictureElement` also works. It wouldn't
// be null in regular picture in picture.
// Exit picture in picture mode. This gesture can't trigger pip on the main window.
this.exitPictureInPicture();
} else if (this.isFullscreen()) {
this.exitFullscreen();
} else {
this.requestFullscreen();
}
}
}
}

@campones
Copy link
Author

sorry but the players's behavior is different between double clicking to go fullscreen and using the fullscreen button,

@gkatsev
Copy link
Member

gkatsev commented Dec 23, 2024

The main difference is that with the dblclick event, you end up getting two click events as well. So, it gets paused and unpaused as part of the gesture. Unfortunately, there isn't a way to prevent this without delaying the normal click event behavior.

Can you elaborate on what you mean by "reset player state"?

@campones
Copy link
Author

exactly. which is quite what I tried to say with my own words
I did a small screen recording which just shows that
https://mega.nz/file/N1Ik3LLY#MpJRy9IKocrBBSY5GnXF3qhwNZOcjFcaLmtUj5ZrwFs

maybe it's not resetting the player state as a whole but it does reset the start time, which make the timer plugin quite useless.

@campones
Copy link
Author

yes the only way would be to be able to delay the start event on a single click to make a difference with a very quick double click I guess. so the player wouldn't off on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: triage This issue needs to be reviewed
Projects
None yet
Development

No branches or pull requests

3 participants