Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
harisha-swaminathan authored Dec 5, 2024
2 parents 6c28487 + ca6f823 commit 556ba81
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 29 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<a name="8.21.0"></a>
# [8.21.0](https://github.com/videojs/video.js/compare/v8.20.0...v8.21.0) (2024-12-05)

### Features

* Add option to disable seeking while scrubbing on mobile ([#8903](https://github.com/videojs/video.js/issues/8903)) ([57d6ab6](https://github.com/videojs/video.js/commit/57d6ab6))

### Bug Fixes

* update vhs version ([#8930](https://github.com/videojs/video.js/issues/8930)) ([f87a699](https://github.com/videojs/video.js/commit/f87a699))

### Chores

* update VHS version ([#8933](https://github.com/videojs/video.js/issues/8933)) ([a7ba9f2](https://github.com/videojs/video.js/commit/a7ba9f2))

<a name="8.20.0"></a>
# [8.20.0](https://github.com/videojs/video.js/compare/v8.19.2...v8.20.0) (2024-11-19)

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Video.js was started in the middle of 2010 and is now used on over ~~50,000~~ ~~
Thanks to the awesome folks over at [Fastly][fastly], there's a free, CDN hosted version of Video.js that anyone can use. Add these tags to your document's `<head>`:

```html
<link href="//vjs.zencdn.net/8.20.0/video-js.min.css" rel="stylesheet">
<script src="//vjs.zencdn.net/8.20.0/video.min.js"></script>
<link href="//vjs.zencdn.net/8.21.0/video-js.min.css" rel="stylesheet">
<script src="//vjs.zencdn.net/8.21.0/video.min.js"></script>
```

Alternatively, you can include Video.js by getting it from [npm](https://videojs.com/getting-started/#install-via-npm), downloading it from [GitHub releases](https://github.com/videojs/video.js/releases) or by including it via [unpkg](https://unpkg.com) or another JavaScript CDN, like CDNjs.
Expand All @@ -34,12 +34,12 @@ Alternatively, you can include Video.js by getting it from [npm](https://videojs
<script src="https://unpkg.com/video.js/dist/video.min.js"></script>

<!-- unpkg : use a specific version of Video.js (change the version numbers as necessary) -->
<link href="https://unpkg.com/video.js@8.20.0/dist/video-js.min.css" rel="stylesheet">
<script src="https://unpkg.com/video.js@8.20.0/dist/video.min.js"></script>
<link href="https://unpkg.com/video.js@8.21.0/dist/video-js.min.css" rel="stylesheet">
<script src="https://unpkg.com/video.js@8.21.0/dist/video.min.js"></script>

<!-- cdnjs : use a specific version of Video.js (change the version numbers as necessary) -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/video.js/8.20.0/video-js.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/8.20.0/video.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/video.js/8.21.0/video-js.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/8.21.0/video.min.js"></script>
```

Next, using Video.js is as simple as creating a `<video>` element, but with an additional `data-setup` attribute. At a minimum, this attribute must have a value of `'{}'`, but it can include any Video.js [options][options] - just make sure it contains valid JSON!
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "video.js",
"description": "An HTML5 video player that supports HLS and DASH with a common API and skin.",
"version": "8.20.0",
"version": "8.21.0",
"main": "./dist/video.cjs.js",
"module": "./dist/video.es.js",
"style": "./dist/video-js.css",
Expand Down Expand Up @@ -86,7 +86,7 @@
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"@videojs/http-streaming": "^3.16.0",
"@videojs/http-streaming": "^3.16.2",
"@videojs/vhs-utils": "^4.1.1",
"@videojs/xhr": "2.7.0",
"aes-decrypter": "^4.0.2",
Expand Down
10 changes: 8 additions & 2 deletions src/css/components/_progress.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

// This increases the size of the progress holder so there is an increased
// hit area for clicks/touches.
.video-js .vjs-progress-control:hover .vjs-progress-holder {
.video-js .vjs-progress-control:hover .vjs-progress-holder,
.video-js.vjs-scrubbing.vjs-touch-enabled .vjs-progress-control .vjs-progress-holder {
font-size: 1.666666666666666666em;
}

Expand Down Expand Up @@ -143,7 +144,8 @@
}

.video-js .vjs-progress-control:hover .vjs-time-tooltip,
.video-js .vjs-progress-control:hover .vjs-progress-holder:focus .vjs-time-tooltip {
.video-js .vjs-progress-control:hover .vjs-progress-holder:focus .vjs-time-tooltip,
.video-js.vjs-scrubbing.vjs-touch-enabled .vjs-progress-control .vjs-time-tooltip {
display: block;

// Ensure that we maintain a font-size of ~10px.
Expand Down Expand Up @@ -172,6 +174,10 @@
display: block;
}

.video-js.vjs-scrubbing.vjs-touch-enabled .vjs-progress-control .vjs-mouse-display {
display: block;
}

.video-js.vjs-user-inactive .vjs-progress-control .vjs-mouse-display {
visibility: hidden;
opacity: 0;
Expand Down
4 changes: 2 additions & 2 deletions src/js/control-bar/progress-control/progress-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ProgressControl extends Component {
}

this.off(['mousedown', 'touchstart'], this.handleMouseDownHandler_);
this.off(this.el_, 'mousemove', this.handleMouseMove);
this.off(this.el_, ['mousemove', 'touchmove'], this.handleMouseMove);

this.removeListenersAddedOnMousedownAndTouchstart();

Expand Down Expand Up @@ -172,7 +172,7 @@ class ProgressControl extends Component {
}

this.on(['mousedown', 'touchstart'], this.handleMouseDownHandler_);
this.on(this.el_, 'mousemove', this.handleMouseMove);
this.on(this.el_, ['mousemove', 'touchmove'], this.handleMouseMove);
this.removeClass('disabled');

this.enabled_ = true;
Expand Down
50 changes: 42 additions & 8 deletions src/js/control-bar/progress-control/seek-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as Dom from '../../utils/dom.js';
import * as Fn from '../../utils/fn.js';
import {formatTime} from '../../utils/time.js';
import {silencePromise} from '../../utils/promise';
import {merge} from '../../utils/obj';
import document from 'global/document';

/** @import Player from '../../player' */
Expand Down Expand Up @@ -40,7 +41,23 @@ class SeekBar extends Slider {
* The key/value store of player options.
*/
constructor(player, options) {
options = merge(SeekBar.prototype.options_, options);

// Avoid mutating the prototype's `children` array by creating a copy
options.children = [...options.children];

const shouldDisableSeekWhileScrubbingOnMobile = player.options_.disableSeekWhileScrubbingOnMobile && (IS_IOS || IS_ANDROID);

// Add the TimeTooltip as a child if we are on desktop, or on mobile with `disableSeekWhileScrubbingOnMobile: true`
if ((!IS_IOS && !IS_ANDROID) || shouldDisableSeekWhileScrubbingOnMobile) {
options.children.splice(1, 0, 'mouseTimeDisplay');
}

super(player, options);

this.shouldDisableSeekWhileScrubbingOnMobile_ = shouldDisableSeekWhileScrubbingOnMobile;
this.pendingSeekTime_ = null;

this.setEventHandlers_();
}

Expand Down Expand Up @@ -225,6 +242,12 @@ class SeekBar extends Slider {
* The percentage of media played so far (0 to 1).
*/
getPercent() {
// If we have a pending seek time, we are scrubbing on mobile and should set the slider percent
// to reflect the current scrub location.
if (this.pendingSeekTime_) {
return this.pendingSeekTime_ / this.player_.duration();
}

const currentTime = this.getCurrentTime_();
let percent;
const liveTracker = this.player_.liveTracker;
Expand Down Expand Up @@ -260,7 +283,12 @@ class SeekBar extends Slider {
event.stopPropagation();

this.videoWasPlaying = !this.player_.paused();
this.player_.pause();

// Don't pause if we are on mobile and `disableSeekWhileScrubbingOnMobile: true`.
// In that case, playback should continue while the player scrubs to a new location.
if (!this.shouldDisableSeekWhileScrubbingOnMobile_) {
this.player_.pause();
}

super.handleMouseDown(event);
}
Expand Down Expand Up @@ -324,8 +352,12 @@ class SeekBar extends Slider {
}
}

// Set new time (tell player to seek to new time)
this.userSeek_(newTime);
// if on mobile and `disableSeekWhileScrubbingOnMobile: true`, keep track of the desired seek point but we won't initiate the seek until 'touchend'
if (this.shouldDisableSeekWhileScrubbingOnMobile_) {
this.pendingSeekTime_ = newTime;
} else {
this.userSeek_(newTime);
}

if (this.player_.options_.enableSmoothSeeking) {
this.update();
Expand Down Expand Up @@ -371,6 +403,13 @@ class SeekBar extends Slider {
}
this.player_.scrubbing(false);

// If we have a pending seek time, then we have finished scrubbing on mobile and should initiate a seek.
if (this.pendingSeekTime_) {
this.userSeek_(this.pendingSeekTime_);

this.pendingSeekTime_ = null;
}

/**
* Trigger timeupdate because we're done seeking and the time has changed.
* This is particularly useful for if the player is paused to time the time displays.
Expand Down Expand Up @@ -513,10 +552,5 @@ SeekBar.prototype.options_ = {
barName: 'playProgressBar'
};

// MouseTimeDisplay tooltips should not be added to a player on mobile devices
if (!IS_IOS && !IS_ANDROID) {
SeekBar.prototype.options_.children.splice(1, 0, 'mouseTimeDisplay');
}

Component.registerComponent('SeekBar', SeekBar);
export default SeekBar;
3 changes: 2 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -5567,7 +5567,8 @@ Player.prototype.options_ = {
horizontalSeek: false
},
// Default smooth seeking to false
enableSmoothSeeking: false
enableSmoothSeeking: false,
disableSeekWhileScrubbingOnMobile: false
};

TECH_EVENTS_RETRIGGER.forEach(function(event) {
Expand Down
14 changes: 14 additions & 0 deletions test/unit/controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ QUnit.test('SeekBar should be filled on 100% when the video/audio ends', functio
window.cancelAnimationFrame = oldCAF;
});

QUnit.test('Seek bar percent should represent scrub location if we are scrubbing on mobile and have a pending seek time', function(assert) {
const player = TestHelpers.makePlayer();
const seekBar = player.controlBar.progressControl.seekBar;

player.duration(100);
seekBar.pendingSeekTime_ = 20;

assert.equal(seekBar.getPercent(), 0.2, 'seek bar percent set correctly to pending seek time');

seekBar.pendingSeekTime_ = 50;

assert.equal(seekBar.getPercent(), 0.5, 'seek bar percent set correctly to next pending seek time');
});

QUnit.test('playback rate button is hidden by default', function(assert) {
assert.expect(1);

Expand Down
Loading

0 comments on commit 556ba81

Please sign in to comment.