Added play in background for Android

This commit is contained in:
tobias
2016-06-01 17:05:42 +02:00
parent 36f62d333b
commit 2cba8c8eee
2 changed files with 29 additions and 1 deletions

View File

@@ -9,13 +9,14 @@ import java.util.Map;
import java.util.HashMap;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.yqritc.scalablevideoview.ScalableType;
import com.yqritc.scalablevideoview.ScalableVideoView;
public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnPreparedListener, MediaPlayer
.OnErrorListener, MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnCompletionListener {
.OnErrorListener, MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnCompletionListener, LifecycleEventListener {
public enum Events {
EVENT_LOAD_START("onVideoLoadStart"),
@@ -69,6 +70,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
private boolean mMuted = false;
private float mVolume = 1.0f;
private float mRate = 1.0f;
private boolean mPlayInBackground = false;
private boolean mMediaPlayerValid = false; // True if mMediaPlayer is in prepared, started, or paused state.
private int mVideoDuration = 0;
@@ -79,6 +81,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
mThemedReactContext = themedReactContext;
mEventEmitter = themedReactContext.getJSModule(RCTEventEmitter.class);
themedReactContext.addLifecycleEventListener(this);
initializeMediaPlayerIfNeeded();
setSurfaceTextureListener(this);
@@ -244,6 +247,10 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
// setRateModifier(mRate);
}
public void setPlayInBackground(final boolean playInBackground) {
mPlayInBackground = playInBackground;
}
@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayerValid = true;
@@ -311,4 +318,19 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
super.onAttachedToWindow();
setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset);
}
@Override
public void onHostPause() {
if (mMediaPlayer != null && !mPlayInBackground) {
mMediaPlayer.pause();
}
}
@Override
public void onHostResume() {
}
@Override
public void onHostDestroy() {
}
}