Skip to content

Commit

Permalink
Fix native player queue
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill committed Feb 20, 2021
1 parent ba7b32e commit 22a28f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
7 changes: 5 additions & 2 deletions assets/js/plugins/NativeVideoPlayer.staticjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ class NativeVideoPlayer {
this.uri = status.uri;

if (this.uri === null) {
// The uri is null, tell playbackManager to stop playback
this.playbackManager.stop(this);
// If the player was closed manually,
// we need to tell web to stop playback
if (status.didPlayerCloseManually) {
this.playbackManager.stop(this);
}
// Notify web that playback has stopped
this._safelyTriggerEvent('stopped');
} else {
Expand Down
10 changes: 9 additions & 1 deletion components/VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const VideoPlayer = observer(() => {
// Update the player when media type or uri changes
useEffect(() => {
if (rootStore.mediaStore.type === MediaTypes.Video) {
rootStore.didPlayerCloseManually = true;
player.current?.loadAsync({
uri: rootStore.mediaStore.uri
}, {
Expand All @@ -53,6 +54,7 @@ const VideoPlayer = observer(() => {
// Close the player when the store indicates it should stop playback
useEffect(() => {
if (rootStore.mediaStore.shouldStop) {
rootStore.didPlayerCloseManually = false;
player.current?.dismissFullscreenPlayer()
.catch(console.debug);
rootStore.mediaStore.shouldStop = false;
Expand All @@ -70,7 +72,13 @@ const VideoPlayer = observer(() => {
player.current?.presentFullscreenPlayer()
.catch(console.debug);
}}
onPlaybackStatusUpdate={({ isPlaying, positionMillis }) => {
onPlaybackStatusUpdate={({ isPlaying, positionMillis, didJustFinish }) => {
if (didJustFinish) {
rootStore.didPlayerCloseManually = false;
player.current?.dismissFullscreenPlayer()
.catch(console.debug);
return;
}
rootStore.mediaStore.isPlaying = isPlaying;
rootStore.mediaStore.positionTicks = msToTicks(positionMillis);
}}
Expand Down
1 change: 1 addition & 0 deletions screens/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const HomeScreen = observer(() => {
// Report media updates to the video plugin
useEffect(() => {
webview.current?.injectJavaScript(`window.ExpoVideoPlayer && window.ExpoVideoPlayer._reportStatus(${JSON.stringify({
didPlayerCloseManually: rootStore.didPlayerCloseManually,
uri: rootStore.mediaStore.uri,
isPlaying: rootStore.mediaStore.isPlaying,
positionTicks: rootStore.mediaStore.positionTicks,
Expand Down
9 changes: 8 additions & 1 deletion stores/RootStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ export default class RootStore {
*/
isReloadRequired = false

/**
* Was the native player closed manually
*/
didPlayerCloseManually = true

mediaStore = new MediaStore()
serverStore = new ServerStore()
settingStore = new SettingStore()

reset() {
this.isFullscreen = false;
this.isReloadRequired = false;
this.didPlayerCloseManually = true;

this.mediaStore.reset();
this.serverStore.reset();
Expand All @@ -45,5 +51,6 @@ export default class RootStore {
decorate(RootStore, {
storeLoaded: [ ignore, observable ],
isFullscreen: [ ignore, observable ],
isReloadRequired: [ ignore, observable ]
isReloadRequired: [ ignore, observable ],
didPlayerCloseManually: [ ignore, observable ]
});

0 comments on commit 22a28f5

Please sign in to comment.