Android bug fixes on how the video progress was being handled. (#367)

* BUGFIX. Progress Update Handler was being called even when the video was paused. The handler was also being called unnecessarily even after the video has completed and unmounted

* Saved and restored the state of the video during the activity state changed
This commit is contained in:
Ranjan Shrestha 2016-11-04 02:28:01 +05:45 committed by Matt Apperson
parent 9ff2ff8e95
commit cc7b7abdca

View File

@ -90,6 +90,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
private float mVolume = 1.0f; private float mVolume = 1.0f;
private float mRate = 1.0f; private float mRate = 1.0f;
private boolean mPlayInBackground = false; private boolean mPlayInBackground = false;
private boolean mActiveStatePauseStatus = false;
private int mMainVer = 0; private int mMainVer = 0;
private int mPatchVer = 0; private int mPatchVer = 0;
@ -115,16 +116,18 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
@Override @Override
public void run() { public void run() {
if (mMediaPlayerValid && !isCompleted) { if (mMediaPlayerValid && !isCompleted &&!mPaused) {
WritableMap event = Arguments.createMap(); WritableMap event = Arguments.createMap();
event.putDouble(EVENT_PROP_CURRENT_TIME, mMediaPlayer.getCurrentPosition() / 1000.0); event.putDouble(EVENT_PROP_CURRENT_TIME, mMediaPlayer.getCurrentPosition() / 1000.0);
event.putDouble(EVENT_PROP_PLAYABLE_DURATION, mVideoBufferedDuration / 1000.0); //TODO:mBufferUpdateRunnable event.putDouble(EVENT_PROP_PLAYABLE_DURATION, mVideoBufferedDuration / 1000.0); //TODO:mBufferUpdateRunnable
mEventEmitter.receiveEvent(getId(), Events.EVENT_PROGRESS.toString(), event); mEventEmitter.receiveEvent(getId(), Events.EVENT_PROGRESS.toString(), event);
// Check for update after an interval
// TODO: The update interval is fixed at 250. There is a property in React component that defines this value. Totally ignored !!!
mProgressUpdateHandler.postDelayed(mProgressUpdateRunnable, 250);
} }
mProgressUpdateHandler.postDelayed(mProgressUpdateRunnable, 250);
} }
}; };
mProgressUpdateHandler.post(mProgressUpdateRunnable);
} }
@Override @Override
@ -298,6 +301,9 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
} else { } else {
if (!mMediaPlayer.isPlaying()) { if (!mMediaPlayer.isPlaying()) {
start(); start();
// Also Start the Progress Update Handler
mProgressUpdateHandler.post(mProgressUpdateRunnable);
} }
} }
} }
@ -499,14 +505,26 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
@Override @Override
public void onHostPause() { public void onHostPause() {
if (mMediaPlayer != null && !mPlayInBackground) { if (mMediaPlayer != null && !mPlayInBackground) {
mMediaPlayer.pause(); mActiveStatePauseStatus = mPaused;
// Pause the video in background
setPausedModifier(true);
} }
} }
@Override @Override
public void onHostResume() { public void onHostResume() {
if (mMediaPlayer != null && !mPlayInBackground) {
new Handler().post(new Runnable() {
@Override
public void run() {
// Restore original state
setPausedModifier(mActiveStatePauseStatus);
}
});
}
} }
@Override @Override