Skip to content

Commit 1fff5c0

Browse files
dzianis-dashkevichDzianis Dashkevich
andauthored
chore: update player public interface for types visibility (#8525)
Co-authored-by: Dzianis Dashkevich <ddashkevich@brightcove.com>
1 parent 6a5e1ee commit 1fff5c0

File tree

1 file changed

+86
-74
lines changed

1 file changed

+86
-74
lines changed

src/js/player.js

Lines changed: 86 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,6 +2621,92 @@ class Player extends Component {
26212621
return buffered;
26222622
}
26232623

2624+
/**
2625+
* Get the TimeRanges of the media that are currently available
2626+
* for seeking to.
2627+
*
2628+
* @see [Seekable Spec]{@link https://html.spec.whatwg.org/multipage/media.html#dom-media-seekable}
2629+
*
2630+
* @return { import('./utils/time').TimeRange }
2631+
* A mock {@link TimeRanges} object (following HTML spec)
2632+
*/
2633+
seekable() {
2634+
let seekable = this.techGet_('seekable');
2635+
2636+
if (!seekable || !seekable.length) {
2637+
seekable = createTimeRange(0, 0);
2638+
}
2639+
2640+
return seekable;
2641+
}
2642+
2643+
/**
2644+
* Returns whether the player is in the "seeking" state.
2645+
*
2646+
* @return {boolean} True if the player is in the seeking state, false if not.
2647+
*/
2648+
seeking() {
2649+
return this.techGet_('seeking');
2650+
}
2651+
2652+
/**
2653+
* Returns whether the player is in the "ended" state.
2654+
*
2655+
* @return {boolean} True if the player is in the ended state, false if not.
2656+
*/
2657+
ended() {
2658+
return this.techGet_('ended');
2659+
}
2660+
2661+
/**
2662+
* Returns the current state of network activity for the element, from
2663+
* the codes in the list below.
2664+
* - NETWORK_EMPTY (numeric value 0)
2665+
* The element has not yet been initialised. All attributes are in
2666+
* their initial states.
2667+
* - NETWORK_IDLE (numeric value 1)
2668+
* The element's resource selection algorithm is active and has
2669+
* selected a resource, but it is not actually using the network at
2670+
* this time.
2671+
* - NETWORK_LOADING (numeric value 2)
2672+
* The user agent is actively trying to download data.
2673+
* - NETWORK_NO_SOURCE (numeric value 3)
2674+
* The element's resource selection algorithm is active, but it has
2675+
* not yet found a resource to use.
2676+
*
2677+
* @see https://html.spec.whatwg.org/multipage/embedded-content.html#network-states
2678+
* @return {number} the current network activity state
2679+
*/
2680+
networkState() {
2681+
return this.techGet_('networkState');
2682+
}
2683+
2684+
/**
2685+
* Returns a value that expresses the current state of the element
2686+
* with respect to rendering the current playback position, from the
2687+
* codes in the list below.
2688+
* - HAVE_NOTHING (numeric value 0)
2689+
* No information regarding the media resource is available.
2690+
* - HAVE_METADATA (numeric value 1)
2691+
* Enough of the resource has been obtained that the duration of the
2692+
* resource is available.
2693+
* - HAVE_CURRENT_DATA (numeric value 2)
2694+
* Data for the immediate current playback position is available.
2695+
* - HAVE_FUTURE_DATA (numeric value 3)
2696+
* Data for the immediate current playback position is available, as
2697+
* well as enough data for the user agent to advance the current
2698+
* playback position in the direction of playback.
2699+
* - HAVE_ENOUGH_DATA (numeric value 4)
2700+
* The user agent estimates that enough data is available for
2701+
* playback to proceed uninterrupted.
2702+
*
2703+
* @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-readystate
2704+
* @return {number} the current playback rendering state
2705+
*/
2706+
readyState() {
2707+
return this.techGet_('readyState');
2708+
}
2709+
26242710
/**
26252711
* Get the percent (as a decimal) of the video that's been downloaded.
26262712
* This method is not a part of the native HTML video API.
@@ -5330,80 +5416,6 @@ Player.prototype.options_ = {
53305416
audioPosterMode: false
53315417
};
53325418

5333-
[
5334-
/**
5335-
* Returns whether or not the player is in the "ended" state.
5336-
*
5337-
* @return {Boolean} True if the player is in the ended state, false if not.
5338-
* @method Player#ended
5339-
*/
5340-
'ended',
5341-
/**
5342-
* Returns whether or not the player is in the "seeking" state.
5343-
*
5344-
* @return {Boolean} True if the player is in the seeking state, false if not.
5345-
* @method Player#seeking
5346-
*/
5347-
'seeking',
5348-
/**
5349-
* Returns the TimeRanges of the media that are currently available
5350-
* for seeking to.
5351-
*
5352-
* @return {TimeRanges} the seekable intervals of the media timeline
5353-
* @method Player#seekable
5354-
*/
5355-
'seekable',
5356-
/**
5357-
* Returns the current state of network activity for the element, from
5358-
* the codes in the list below.
5359-
* - NETWORK_EMPTY (numeric value 0)
5360-
* The element has not yet been initialised. All attributes are in
5361-
* their initial states.
5362-
* - NETWORK_IDLE (numeric value 1)
5363-
* The element's resource selection algorithm is active and has
5364-
* selected a resource, but it is not actually using the network at
5365-
* this time.
5366-
* - NETWORK_LOADING (numeric value 2)
5367-
* The user agent is actively trying to download data.
5368-
* - NETWORK_NO_SOURCE (numeric value 3)
5369-
* The element's resource selection algorithm is active, but it has
5370-
* not yet found a resource to use.
5371-
*
5372-
* @see https://html.spec.whatwg.org/multipage/embedded-content.html#network-states
5373-
* @return {number} the current network activity state
5374-
* @method Player#networkState
5375-
*/
5376-
'networkState',
5377-
/**
5378-
* Returns a value that expresses the current state of the element
5379-
* with respect to rendering the current playback position, from the
5380-
* codes in the list below.
5381-
* - HAVE_NOTHING (numeric value 0)
5382-
* No information regarding the media resource is available.
5383-
* - HAVE_METADATA (numeric value 1)
5384-
* Enough of the resource has been obtained that the duration of the
5385-
* resource is available.
5386-
* - HAVE_CURRENT_DATA (numeric value 2)
5387-
* Data for the immediate current playback position is available.
5388-
* - HAVE_FUTURE_DATA (numeric value 3)
5389-
* Data for the immediate current playback position is available, as
5390-
* well as enough data for the user agent to advance the current
5391-
* playback position in the direction of playback.
5392-
* - HAVE_ENOUGH_DATA (numeric value 4)
5393-
* The user agent estimates that enough data is available for
5394-
* playback to proceed uninterrupted.
5395-
*
5396-
* @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-readystate
5397-
* @return {number} the current playback rendering state
5398-
* @method Player#readyState
5399-
*/
5400-
'readyState'
5401-
].forEach(function(fn) {
5402-
Player.prototype[fn] = function() {
5403-
return this.techGet_(fn);
5404-
};
5405-
});
5406-
54075419
TECH_EVENTS_RETRIGGER.forEach(function(event) {
54085420
Player.prototype[`handleTech${toTitleCase(event)}_`] = function() {
54095421
return this.trigger(event);

0 commit comments

Comments
 (0)