Skip to content

Commit

Permalink
feat: Add an option to prevent clicks from toggling playback (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
adribarbeito committed Jun 15, 2021
1 parent 9293eb4 commit 7dc2684
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Maintenance Status: Stable
- [`debug`](#debug)
- [`omnitone`](#omnitone)
- [`omnitoneOptions`](#omnitoneoptions)
- [`disableTogglePlay`](#disableTogglePlay)
- [Credits](#credits)
- [Support](#support)

Expand Down Expand Up @@ -276,6 +277,12 @@ Please be aware of, the Omnitone library is not included in the build files.
Default options for the Omnitone library. Please check available options on https://github.com/GoogleChrome/omnitone

### `disableTogglePlay`

> type: `boolean`, default: `false`
Feature to disable the togglePlay manually.
This functionality is useful in live events so that users cannot stop the live, but still have a controlBar available.

## Credits ##

Expand Down
29 changes: 29 additions & 0 deletions examples/disable-togglePlay.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>videojs-vr Demo disabled tooglePlay</title>
<link href="../node_modules/video.js/dist/video-js.css" rel="stylesheet">
<link href="../dist/videojs-vr.css" rel="stylesheet">
</head>
<body>
<video width="640" height="300" id="videojs-vr-player" class="video-js vjs-default-skin" crossorigin="anonymous" controls playsinline>
<source src="https://storage.googleapis.com/omnitone-demo.google.com.a.appspot.com/fuerza-imprevista-1080p-h264-aac.mp4" type="video/mp4">
</video>
<ul>
<li><a href="../">return to main example</a></li>
</ul>
<script src="../node_modules/video.js/dist/video.js"></script>
<script src="../dist/videojs-vr.js"></script>
<script>
(function(window, videojs) {
var player = window.player = videojs('videojs-vr-player');
player.mediainfo = player.mediainfo || {};
player.mediainfo.projection = '360';

// AUTO is the default and looks at mediainfo
var vr = window.vr = player.vr({projection: 'AUTO', disableTogglePlay: true, debug: true, forceCardboard: false});
}(window, window.videojs));
</script>
</body>
</html>
5 changes: 3 additions & 2 deletions src/canvas-player-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import videojs from 'video.js';
* show the control bar. Moving around the scene in the canvas should not.
*/
class CanvasPlayerControls extends videojs.EventTarget {
constructor(player, canvas) {
constructor(player, canvas, options) {
super();

this.player = player;
this.canvas = canvas;
this.options = options;

this.onMoveEnd = videojs.bind(this, this.onMoveEnd);
this.onMoveStart = videojs.bind(this, this.onMoveStart);
Expand Down Expand Up @@ -61,7 +62,7 @@ class CanvasPlayerControls extends videojs.EventTarget {
// if the player does not have a controlbar or
// the move was a mouse click but not left click do not
// toggle play.
if (!this.player.controls() || (e.type === 'mousedown' && !videojs.dom.isSingleLeftClick(e))) {
if (this.options.disableTogglePlay || !this.player.controls() || (e.type === 'mousedown' && !videojs.dom.isSingleLeftClick(e))) {
this.shouldTogglePlay = false;
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const defaults = {
forceCardboard: false,
omnitoneOptions: {},
projection: 'AUTO',
sphereDetail: 32
sphereDetail: 32,
disableTogglePlay: false
};

const errors = {
Expand Down Expand Up @@ -730,7 +731,7 @@ void main() {
}

this.controls3d = new OrbitOrientationContols(options);
this.canvasPlayerControls = new CanvasPlayerControls(this.player_, this.renderedCanvas);
this.canvasPlayerControls = new CanvasPlayerControls(this.player_, this.renderedCanvas, this.options_);
}

this.animationFrameId_ = this.requestAnimationFrame(this.animate_);
Expand Down

0 comments on commit 7dc2684

Please sign in to comment.