[Android] Simplify src assignment
This commit is contained in:
parent
a52f1d5dcf
commit
93b426c753
@ -49,8 +49,9 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
|
|||||||
private Handler mProgressUpdateHandler = new Handler();
|
private Handler mProgressUpdateHandler = new Handler();
|
||||||
private Runnable mProgressUpdateRunnable = null;
|
private Runnable mProgressUpdateRunnable = null;
|
||||||
|
|
||||||
private String mUriString = null;
|
private String mSrcUriString = null;
|
||||||
private boolean mIsNetwork = false;
|
private String mSrcType = "mp4";
|
||||||
|
private boolean mSrcIsNetwork = false;
|
||||||
private ScalableType mResizeMode = ScalableType.LEFT_TOP;
|
private ScalableType mResizeMode = ScalableType.LEFT_TOP;
|
||||||
private boolean mRepeat = false;
|
private boolean mRepeat = false;
|
||||||
private boolean mPaused = 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 {
|
public void setSrc(final String uriString, final String type, final boolean isNetwork) {
|
||||||
mUriString = uriString;
|
mSrcUriString = uriString;
|
||||||
mIsNetwork = isNetwork;
|
mSrcType = type;
|
||||||
|
mSrcIsNetwork = isNetwork;
|
||||||
|
|
||||||
mMediaPlayerValid = false;
|
mMediaPlayerValid = false;
|
||||||
mVideoDuration = 0;
|
mVideoDuration = 0;
|
||||||
@ -110,16 +112,29 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
|
|||||||
initializeMediaPlayerIfNeeded();
|
initializeMediaPlayerIfNeeded();
|
||||||
mMediaPlayer.reset();
|
mMediaPlayer.reset();
|
||||||
|
|
||||||
if (isNetwork) {
|
try {
|
||||||
setDataSource(uriString);
|
if (isNetwork) {
|
||||||
} else {
|
setDataSource(uriString);
|
||||||
setRawData(mThemedReactContext.getResources().getIdentifier(
|
} else {
|
||||||
uriString,
|
setRawData(mThemedReactContext.getResources().getIdentifier(
|
||||||
"raw",
|
uriString,
|
||||||
mThemedReactContext.getPackageName()
|
"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);
|
prepareAsync(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,11 +262,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
|
|||||||
@Override
|
@Override
|
||||||
protected void onAttachedToWindow() {
|
protected void onAttachedToWindow() {
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
|
setSrc(mSrcUriString, mSrcType, mSrcIsNetwork);
|
||||||
try {
|
|
||||||
setSrc(mUriString, mIsNetwork);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,29 +63,11 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
|
|||||||
|
|
||||||
@ReactProp(name = PROP_SRC)
|
@ReactProp(name = PROP_SRC)
|
||||||
public void setSrc(final ReactVideoView videoView, @Nullable ReadableMap src) {
|
public void setSrc(final ReactVideoView videoView, @Nullable ReadableMap src) {
|
||||||
final ThemedReactContext themedReactContext = (ThemedReactContext) videoView.getContext();
|
videoView.setSrc(
|
||||||
final RCTEventEmitter eventEmitter = themedReactContext.getJSModule(RCTEventEmitter.class);
|
src.getString(PROP_SRC_URI),
|
||||||
|
src.getString(PROP_SRC_TYPE),
|
||||||
try {
|
src.getBoolean(PROP_SRC_IS_NETWORK)
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactProp(name = PROP_RESIZE_MODE)
|
@ReactProp(name = PROP_RESIZE_MODE)
|
||||||
|
Loading…
Reference in New Issue
Block a user