feat: add seekToMode override

adds optional seekToMode parameter that allows the behaviour of seekTo to be controlled.
This commit is contained in:
Wlad Meixner
2024-02-15 09:56:52 +01:00
parent 79b595710d
commit 4dee39c6cf
13 changed files with 91 additions and 65 deletions
+3 -3
View File
@@ -1,9 +1,9 @@
# AUTO GENERATED FILE - DO NOT EDIT
#' @export
dashPlayer <- function(id=NULL, className=NULL, controls=NULL, currentTime=NULL, duration=NULL, height=NULL, intervalCurrentTime=NULL, intervalDuration=NULL, intervalSecondsLoaded=NULL, loop=NULL, muted=NULL, playbackRate=NULL, playing=NULL, playsinline=NULL, secondsLoaded=NULL, seekTo=NULL, style=NULL, url=NULL, volume=NULL, width=NULL) {
dashPlayer <- function(id=NULL, className=NULL, controls=NULL, currentTime=NULL, duration=NULL, height=NULL, intervalCurrentTime=NULL, intervalDuration=NULL, intervalSecondsLoaded=NULL, loop=NULL, muted=NULL, playbackRate=NULL, playing=NULL, playsinline=NULL, secondsLoaded=NULL, seekTo=NULL, seekToMode=NULL, style=NULL, url=NULL, volume=NULL, width=NULL) {
props <- list(id=id, className=className, controls=controls, currentTime=currentTime, duration=duration, height=height, intervalCurrentTime=intervalCurrentTime, intervalDuration=intervalDuration, intervalSecondsLoaded=intervalSecondsLoaded, loop=loop, muted=muted, playbackRate=playbackRate, playing=playing, playsinline=playsinline, secondsLoaded=secondsLoaded, seekTo=seekTo, style=style, url=url, volume=volume, width=width)
props <- list(id=id, className=className, controls=controls, currentTime=currentTime, duration=duration, height=height, intervalCurrentTime=intervalCurrentTime, intervalDuration=intervalDuration, intervalSecondsLoaded=intervalSecondsLoaded, loop=loop, muted=muted, playbackRate=playbackRate, playing=playing, playsinline=playsinline, secondsLoaded=secondsLoaded, seekTo=seekTo, seekToMode=seekToMode, style=style, url=url, volume=volume, width=width)
if (length(props) > 0) {
props <- props[!vapply(props, is.null, logical(1))]
}
@@ -11,7 +11,7 @@ dashPlayer <- function(id=NULL, className=NULL, controls=NULL, currentTime=NULL,
props = props,
type = 'DashPlayer',
namespace = 'dash_player',
propNames = c('id', 'className', 'controls', 'currentTime', 'duration', 'height', 'intervalCurrentTime', 'intervalDuration', 'intervalSecondsLoaded', 'loop', 'muted', 'playbackRate', 'playing', 'playsinline', 'secondsLoaded', 'seekTo', 'style', 'url', 'volume', 'width'),
propNames = c('id', 'className', 'controls', 'currentTime', 'duration', 'height', 'intervalCurrentTime', 'intervalDuration', 'intervalSecondsLoaded', 'loop', 'muted', 'playbackRate', 'playing', 'playsinline', 'secondsLoaded', 'seekTo', 'seekToMode', 'style', 'url', 'volume', 'width'),
package = 'dashPlayer'
)
+8 -3
View File
@@ -68,6 +68,11 @@ Keyword arguments:
Seek to the given number of seconds, or fraction if amount is
between 0 and 1.
- seekToMode (string; default undefined):
Seek to mode (can be \"seconds\" or \"fraction\"), overwrites
default behaviour of seekTo that uses fraction or seconds
depending on value.
- style (dict; optional):
Optional additional CSS styles. If width or height are supplied
within style, then this will override the component-level width or
@@ -87,10 +92,10 @@ Keyword arguments:
_namespace = 'dash_player'
_type = 'DashPlayer'
@_explicitize_args
def __init__(self, id=Component.UNDEFINED, className=Component.UNDEFINED, url=Component.UNDEFINED, playing=Component.UNDEFINED, loop=Component.UNDEFINED, controls=Component.UNDEFINED, volume=Component.UNDEFINED, muted=Component.UNDEFINED, playbackRate=Component.UNDEFINED, width=Component.UNDEFINED, height=Component.UNDEFINED, style=Component.UNDEFINED, playsinline=Component.UNDEFINED, currentTime=Component.UNDEFINED, secondsLoaded=Component.UNDEFINED, duration=Component.UNDEFINED, intervalCurrentTime=Component.UNDEFINED, intervalSecondsLoaded=Component.UNDEFINED, intervalDuration=Component.UNDEFINED, seekTo=Component.UNDEFINED, **kwargs):
self._prop_names = ['id', 'className', 'controls', 'currentTime', 'duration', 'height', 'intervalCurrentTime', 'intervalDuration', 'intervalSecondsLoaded', 'loop', 'muted', 'playbackRate', 'playing', 'playsinline', 'secondsLoaded', 'seekTo', 'style', 'url', 'volume', 'width']
def __init__(self, id=Component.UNDEFINED, className=Component.UNDEFINED, url=Component.UNDEFINED, playing=Component.UNDEFINED, loop=Component.UNDEFINED, controls=Component.UNDEFINED, volume=Component.UNDEFINED, muted=Component.UNDEFINED, playbackRate=Component.UNDEFINED, width=Component.UNDEFINED, height=Component.UNDEFINED, style=Component.UNDEFINED, playsinline=Component.UNDEFINED, currentTime=Component.UNDEFINED, secondsLoaded=Component.UNDEFINED, duration=Component.UNDEFINED, intervalCurrentTime=Component.UNDEFINED, intervalSecondsLoaded=Component.UNDEFINED, intervalDuration=Component.UNDEFINED, seekTo=Component.UNDEFINED, seekToMode=Component.UNDEFINED, **kwargs):
self._prop_names = ['id', 'className', 'controls', 'currentTime', 'duration', 'height', 'intervalCurrentTime', 'intervalDuration', 'intervalSecondsLoaded', 'loop', 'muted', 'playbackRate', 'playing', 'playsinline', 'secondsLoaded', 'seekTo', 'seekToMode', 'style', 'url', 'volume', 'width']
self._valid_wildcard_attributes = []
self.available_properties = ['id', 'className', 'controls', 'currentTime', 'duration', 'height', 'intervalCurrentTime', 'intervalDuration', 'intervalSecondsLoaded', 'loop', 'muted', 'playbackRate', 'playing', 'playsinline', 'secondsLoaded', 'seekTo', 'style', 'url', 'volume', 'width']
self.available_properties = ['id', 'className', 'controls', 'currentTime', 'duration', 'height', 'intervalCurrentTime', 'intervalDuration', 'intervalSecondsLoaded', 'loop', 'muted', 'playbackRate', 'playing', 'playsinline', 'secondsLoaded', 'seekTo', 'seekToMode', 'style', 'url', 'volume', 'width']
self.available_wildcard_properties = []
_explicit_args = kwargs.pop('_explicit_args')
_locals = locals()
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+5 -1
View File
@@ -15,7 +15,8 @@ duration=NULL, height=NULL, intervalCurrentTime=NULL,
intervalDuration=NULL, intervalSecondsLoaded=NULL,
loop=NULL, muted=NULL, playbackRate=NULL, playing=NULL,
playsinline=NULL, secondsLoaded=NULL, seekTo=NULL,
style=NULL, url=NULL, volume=NULL, width=NULL)
seekToMode=NULL, style=NULL, url=NULL, volume=NULL,
width=NULL)
}
\arguments{
@@ -58,6 +59,9 @@ mode when playback begins (for iOS).}
\item{seekTo}{Numeric. Seek to the given number of seconds, or fraction if amount is between 0 and 1}
\item{seekToMode}{Character. Seek to mode (can be "seconds" or "fraction"), overwrites default behaviour
of seekTo that uses fraction or seconds depending on value.}
\item{style}{Named list. Optional additional CSS styles. If width or height are supplied within style,
then this will override the component-level width or height}
+17 -5
View File
@@ -1,7 +1,12 @@
import React, {Component, lazy, Suspense} from 'react';
import React, { Component, lazy, Suspense } from 'react';
import PropTypes from 'prop-types';
const RealDashPlayer = lazy(() => import(/* webpackChunkName: "dashplayer" */ '../fragments/DashPlayer.react'));
const RealDashPlayer = lazy(
() =>
import(
/* webpackChunkName: "dashplayer" */ '../fragments/DashPlayer.react'
)
);
/**
* A Dash component for playing a variety of URLs, including file paths,
@@ -28,8 +33,9 @@ DashPlayer.defaultProps = {
playbackRate: 1,
width: '640px',
height: '360px',
style:{},
style: {},
playsinline: false,
seekToMode: undefined,
seekTo: null,
intervalCurrentTime: 100,
intervalSecondsLoaded: 500,
@@ -152,8 +158,14 @@ DashPlayer.propTypes = {
/**
* Seek to the given number of seconds, or fraction if amount is between 0 and 1
*/
seekTo: PropTypes.number
seekTo: PropTypes.number,
/**
* Seek to mode (can be "seconds" or "fraction"), overwrites default behaviour
* of seekTo that uses fraction or seconds depending on value.
*/
seekToMode: PropTypes.string
};
export const propTypes = DashPlayer.propTypes;
export const defaultProps = DashPlayer.defaultProps;
export const defaultProps = DashPlayer.defaultProps;
+50 -45
View File
@@ -1,6 +1,6 @@
import React, {Component} from 'react';
import React, { Component } from 'react';
import ReactPlayer from 'react-player';
import {propTypes, defaultProps} from '../components/DashPlayer.react';
import { propTypes, defaultProps } from '../components/DashPlayer.react';
export default class DashPlayer extends Component {
constructor(props) {
@@ -11,37 +11,38 @@ export default class DashPlayer extends Component {
this.updateDuration = this.updateDuration.bind(this);
this.updateIntervals = this.updateIntervals.bind(this);
this.setSeekTo = this.setSeekTo.bind(this);
this.ref = this.ref.bind(this);
}
updateCurrentTime(){
const {setProps} = this.props;
if (this.refs.player !== null){
const currentTime = this.refs.player.getCurrentTime();
updateCurrentTime() {
const { setProps } = this.props;
if (this.player !== null) {
const currentTime = this.player.getCurrentTime();
if (typeof setProps === 'function') {
setProps({currentTime: currentTime});
if (typeof setProps === 'function') {
setProps({ currentTime: currentTime });
}
}
}
updateSecondsLoaded(){
const {setProps} = this.props;
if (this.refs.player !== null){
const secondsLoaded = this.refs.player.getSecondsLoaded();
updateSecondsLoaded() {
const { setProps } = this.props;
if (this.player !== null) {
const secondsLoaded = this.player.getSecondsLoaded();
if (typeof setProps === 'function') {
setProps({secondsLoaded: secondsLoaded});
if (typeof setProps === 'function') {
setProps({ secondsLoaded: secondsLoaded });
}
}
}
updateDuration(){
const {setProps} = this.props;
if (this.refs.player !== null){
const duration = this.refs.player.getDuration();
updateDuration() {
const { setProps } = this.props;
if (this.player !== null) {
const duration = this.player.getDuration();
if (typeof setProps === 'function'){
setProps({duration: duration});
if (typeof setProps === 'function') {
setProps({ duration: duration });
}
}
}
@@ -51,32 +52,35 @@ export default class DashPlayer extends Component {
* assigned handle and set it to the new interval value. It works for
* currentTime, duration and secondsLoaded.
*/
updateIntervals(prevProps){
const {
intervalCurrentTime,
intervalDuration,
intervalSecondsLoaded
} = this.props;
updateIntervals(prevProps) {
const { intervalCurrentTime, intervalDuration, intervalSecondsLoaded } =
this.props;
// Update interval of current time
if (typeof this.handleCurrentTime === 'undefined' ||
prevProps.intervalCurrentTime !== intervalCurrentTime){
if (
typeof this.handleCurrentTime === 'undefined' ||
prevProps.intervalCurrentTime !== intervalCurrentTime
) {
clearInterval(this.handleCurrentTime);
this.handleCurrentTime = setInterval(
this.updateCurrentTime,
intervalCurrentTime
);
}
if (typeof this.handleDuration === 'undefined' ||
prevProps.intervalDuration !== intervalDuration){
if (
typeof this.handleDuration === 'undefined' ||
prevProps.intervalDuration !== intervalDuration
) {
clearInterval(this.handleDuration);
this.handleDuration = setInterval(
this.updateDuration,
intervalDuration
);
}
if (typeof this.handleSecondsLoaded === 'undefined' ||
prevProps.intervalSecondsLoaded !== intervalSecondsLoaded){
if (
typeof this.handleSecondsLoaded === 'undefined' ||
prevProps.intervalSecondsLoaded !== intervalSecondsLoaded
) {
clearInterval(this.handleSecondsLoaded);
this.handleSecondsLoaded = setInterval(
this.updateSecondsLoaded,
@@ -90,25 +94,26 @@ export default class DashPlayer extends Component {
* contains any value, then set seekTo to null. If seekTo was already
* null, it doesn't do anything.
*/
setSeekTo(){
const {
seekTo,
setProps
} = this.props;
if (seekTo !== null && typeof setProps === 'function'){
this.refs.player.seekTo(seekTo);
setProps({seekTo: null});
setSeekTo() {
const { seekTo, setProps, seekToMode } = this.props;
console.log(seekToMode);
if (seekTo !== null && typeof setProps === 'function') {
this.player.seekTo(seekTo, seekToMode);
setProps({ seekTo: null });
}
}
componentDidUpdate(prevProps){
componentDidUpdate(prevProps) {
this.updateIntervals(prevProps);
this.setSeekTo();
}
componentDidMount() {
this.updateDuration()
this.updateDuration();
}
ref(player) {
this.player = player;
}
render() {
@@ -130,7 +135,7 @@ export default class DashPlayer extends Component {
return (
<ReactPlayer
ref="player"
ref={this.ref}
id={id}
url={url}
playing={playing}
@@ -150,4 +155,4 @@ export default class DashPlayer extends Component {
}
DashPlayer.defaultProps = defaultProps;
DashPlayer.propTypes = propTypes;
DashPlayer.propTypes = propTypes;