VEX-6350: add onPlaybackStateChanged prop (#25)

* Adds the new prop onPlaybackStateChanged
This commit is contained in:
Gabriel Rivero 2022-04-19 12:12:47 -04:00 committed by GitHub
parent f78c623df4
commit 03f77495fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 1 deletions

View File

@ -332,6 +332,7 @@ var styles = StyleSheet.create({
* [onFullscreenPlayerDidDismiss](#onfullscreenplayerdiddismiss) * [onFullscreenPlayerDidDismiss](#onfullscreenplayerdiddismiss)
* [onLoad](#onload) * [onLoad](#onload)
* [onLoadStart](#onloadstart) * [onLoadStart](#onloadstart)
* [onPlaybackStateChanged]($onPlaybackStateChanged)
* [onReadyForDisplay](#onreadyfordisplay) * [onReadyForDisplay](#onreadyfordisplay)
* [onPictureInPictureStatusChanged](#onpictureinpicturestatuschanged) * [onPictureInPictureStatusChanged](#onpictureinpicturestatuschanged)
* [onPlaybackRateChange](#onplaybackratechange) * [onPlaybackRateChange](#onplaybackratechange)
@ -1110,6 +1111,24 @@ Example:
Platforms: all Platforms: all
#### onPlaybackStateChanged
Callback function that is called when the playback state changes.
Payload:
Property | Description
--- | ---
isPlaying | boolean | Boolean indicating if the media is playing or not
Example:
```
{
isPlaying: true,
}
```
Platforms: Android ExoPlayer
#### onReadyForDisplay #### onReadyForDisplay
Callback function that is called when the first video frame is ready for display. This is when the poster is removed. Callback function that is called when the first video frame is ready for display. This is when the poster is removed.

View File

@ -99,6 +99,12 @@ export default class Video extends Component {
} }
}; };
_onPlaybackStateChanged = (event) => {
if (this.props.onPlaybackStateChanged) {
this.props.onPlaybackStateChanged(event.nativeEvent);
}
};
_onLoad = (event) => { _onLoad = (event) => {
// Need to hide poster here for windows as onReadyForDisplay is not implemented // Need to hide poster here for windows as onReadyForDisplay is not implemented
if (Platform.OS === 'windows') { if (Platform.OS === 'windows') {
@ -311,6 +317,7 @@ export default class Video extends Component {
requestHeaders: source.headers ? this.stringsOnlyObject(source.headers) : {}, requestHeaders: source.headers ? this.stringsOnlyObject(source.headers) : {},
}, },
onVideoLoadStart: this._onLoadStart, onVideoLoadStart: this._onLoadStart,
onVideoPlaybackStateChanged: this._onPlaybackStateChanged,
onVideoLoad: this._onLoad, onVideoLoad: this._onLoad,
onVideoError: this._onError, onVideoError: this._onError,
onVideoProgress: this._onProgress, onVideoProgress: this._onProgress,
@ -491,6 +498,7 @@ Video.propTypes = {
useSecureView: PropTypes.bool, useSecureView: PropTypes.bool,
hideShutterView: PropTypes.bool, hideShutterView: PropTypes.bool,
onLoadStart: PropTypes.func, onLoadStart: PropTypes.func,
onPlaybackStateChanged: PropTypes.func,
onLoad: PropTypes.func, onLoad: PropTypes.func,
onBuffer: PropTypes.func, onBuffer: PropTypes.func,
onError: PropTypes.func, onError: PropTypes.func,

View File

@ -1243,6 +1243,11 @@ class ReactExoplayerView extends FrameLayout implements
eventEmitter.playbackRateChange(params.speed); eventEmitter.playbackRateChange(params.speed);
} }
@Override
public void onIsPlayingChanged(boolean isPlaying) {
eventEmitter.playbackStateChanged(isPlaying);
}
@Override @Override
public void onPlayerError(ExoPlaybackException e) { public void onPlayerError(ExoPlaybackException e) {
String errorString = "ExoPlaybackException type : " + e.type; String errorString = "ExoPlaybackException type : " + e.type;

View File

@ -44,6 +44,7 @@ class VideoEventEmitter {
private static final String EVENT_RESUME = "onPlaybackResume"; private static final String EVENT_RESUME = "onPlaybackResume";
private static final String EVENT_READY = "onReadyForDisplay"; private static final String EVENT_READY = "onReadyForDisplay";
private static final String EVENT_BUFFER = "onVideoBuffer"; private static final String EVENT_BUFFER = "onVideoBuffer";
private static final String EVENT_PLAYBACK_STATE_CHANGED = "onVideoPlaybackStateChanged";
private static final String EVENT_BUFFER_PROGRESS = "onVideoBufferProgress"; private static final String EVENT_BUFFER_PROGRESS = "onVideoBufferProgress";
private static final String EVENT_IDLE = "onVideoIdle"; private static final String EVENT_IDLE = "onVideoIdle";
private static final String EVENT_TIMED_METADATA = "onTimedMetadata"; private static final String EVENT_TIMED_METADATA = "onTimedMetadata";
@ -66,6 +67,7 @@ class VideoEventEmitter {
EVENT_RESUME, EVENT_RESUME,
EVENT_READY, EVENT_READY,
EVENT_BUFFER, EVENT_BUFFER,
EVENT_PLAYBACK_STATE_CHANGED,
EVENT_BUFFER_PROGRESS, EVENT_BUFFER_PROGRESS,
EVENT_IDLE, EVENT_IDLE,
EVENT_TIMED_METADATA, EVENT_TIMED_METADATA,
@ -91,6 +93,7 @@ class VideoEventEmitter {
EVENT_RESUME, EVENT_RESUME,
EVENT_READY, EVENT_READY,
EVENT_BUFFER, EVENT_BUFFER,
EVENT_PLAYBACK_STATE_CHANGED,
EVENT_BUFFER_PROGRESS, EVENT_BUFFER_PROGRESS,
EVENT_IDLE, EVENT_IDLE,
EVENT_TIMED_METADATA, EVENT_TIMED_METADATA,
@ -139,6 +142,7 @@ class VideoEventEmitter {
private static final String EVENT_PROP_BITRATE = "bitrate"; private static final String EVENT_PROP_BITRATE = "bitrate";
private static final String EVENT_PROP_IS_PLAYING = "isPlaying";
void setViewId(int viewId) { void setViewId(int viewId) {
this.viewId = viewId; this.viewId = viewId;
@ -215,6 +219,12 @@ class VideoEventEmitter {
receiveEvent(EVENT_BUFFER, map); receiveEvent(EVENT_BUFFER, map);
} }
void playbackStateChanged(boolean isPlaying) {
WritableMap map = Arguments.createMap();
map.putBoolean(EVENT_PROP_IS_PLAYING, isPlaying);
receiveEvent(EVENT_PLAYBACK_STATE_CHANGED, map);
}
void bufferProgress(double start, double end) { void bufferProgress(double start, double end) {
WritableMap map = Arguments.createMap(); WritableMap map = Arguments.createMap();
map.putDouble(EVENT_PROP_BUFFER_START, start); map.putDouble(EVENT_PROP_BUFFER_START, start);