diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index a3b16eaf..2478879e 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -49,8 +49,9 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP private Handler mProgressUpdateHandler = new Handler(); private Runnable mProgressUpdateRunnable = null; - private String mUriString = null; - private boolean mIsNetwork = false; + private String mSrcUriString = null; + private String mSrcType = "mp4"; + private boolean mSrcIsNetwork = false; private ScalableType mResizeMode = ScalableType.LEFT_TOP; private boolean mRepeat = false; private boolean mPaused = false; @@ -100,9 +101,10 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP } } - public void setSrc(final String uriString, final boolean isNetwork) throws IOException { - mUriString = uriString; - mIsNetwork = isNetwork; + public void setSrc(final String uriString, final String type, final boolean isNetwork) { + mSrcUriString = uriString; + mSrcType = type; + mSrcIsNetwork = isNetwork; mMediaPlayerValid = false; mVideoDuration = 0; @@ -110,16 +112,29 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP initializeMediaPlayerIfNeeded(); mMediaPlayer.reset(); - if (isNetwork) { - setDataSource(uriString); - } else { - setRawData(mThemedReactContext.getResources().getIdentifier( - uriString, - "raw", - mThemedReactContext.getPackageName() - )); + try { + if (isNetwork) { + setDataSource(uriString); + } else { + setRawData(mThemedReactContext.getResources().getIdentifier( + uriString, + "raw", + mThemedReactContext.getPackageName() + )); + } + } catch (Exception e) { + e.printStackTrace(); + return; } + WritableMap src = Arguments.createMap(); + src.putString(ReactVideoViewManager.PROP_SRC_URI, uriString); + src.putString(ReactVideoViewManager.PROP_SRC_TYPE, type); + src.putBoolean(ReactVideoViewManager.PROP_SRC_IS_NETWORK, isNetwork); + WritableMap event = Arguments.createMap(); + event.putMap(ReactVideoViewManager.PROP_SRC, src); + mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD_START.toString(), event); + prepareAsync(this); } @@ -247,11 +262,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - - try { - setSrc(mUriString, mIsNetwork); - } catch (Exception e) { - e.printStackTrace(); - } + setSrc(mSrcUriString, mSrcType, mSrcIsNetwork); } } diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java b/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java index aa5131ad..3ec693da 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java @@ -63,29 +63,11 @@ public class ReactVideoViewManager extends SimpleViewManager { @ReactProp(name = PROP_SRC) public void setSrc(final ReactVideoView videoView, @Nullable ReadableMap src) { - final ThemedReactContext themedReactContext = (ThemedReactContext) videoView.getContext(); - final RCTEventEmitter eventEmitter = themedReactContext.getJSModule(RCTEventEmitter.class); - - try { - final String uriString = src.getString(PROP_SRC_URI); - final String type = src.getString(PROP_SRC_TYPE); - final boolean isNetwork = src.getBoolean(PROP_SRC_IS_NETWORK); - - // TODO: Carry this inside videoView.setSrc - WritableMap writableSrc = Arguments.createMap(); - writableSrc.putString(PROP_SRC_URI, uriString); - writableSrc.putString(PROP_SRC_TYPE, type); - writableSrc.putBoolean(PROP_SRC_IS_NETWORK, isNetwork); - WritableMap event = Arguments.createMap(); - event.putMap(PROP_SRC, writableSrc); - eventEmitter.receiveEvent(videoView.getId(), Events.EVENT_LOAD_START.toString(), event); - - videoView.setSrc(uriString, isNetwork); - } catch (Exception e) { - // TODO: Send onError - // TODO: Carry inside videoView.setSrc - e.printStackTrace(); - } + videoView.setSrc( + src.getString(PROP_SRC_URI), + src.getString(PROP_SRC_TYPE), + src.getBoolean(PROP_SRC_IS_NETWORK) + ); } @ReactProp(name = PROP_RESIZE_MODE)