[Android] Fix video events

This commit is contained in:
Baris Sencan 2015-11-12 19:27:12 -08:00
parent 9e9e45c1a5
commit 44203ab9d6
2 changed files with 23 additions and 11 deletions

View File

@ -9,6 +9,8 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.yqritc.scalablevideoview.ScalableType;
import com.yqritc.scalablevideoview.ScalableVideoView;
import java.io.IOException;
public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnPreparedListener, MediaPlayer
.OnErrorListener, MediaPlayer.OnCompletionListener {
@ -82,6 +84,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnCompletionListener(this);
}
}
@ -89,6 +92,22 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
mMediaPlayer.reset();
}
public void setSrc(final String uriString, final boolean isNetwork) throws IOException {
reset();
if (isNetwork) {
setDataSource(uriString);
} else {
setRawData(mThemedReactContext.getResources().getIdentifier(
uriString,
"raw",
mThemedReactContext.getPackageName()
));
}
prepare(this);
}
public void setResizeModeModifier(final ScalableType resizeMode) {
mResizeMode = resizeMode;
initializeMediaPlayerIfNeeded();

View File

@ -1,6 +1,5 @@
package com.brentvatne.react;
import android.content.Context;
import com.brentvatne.react.ReactVideoView.Events;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableMap;
@ -70,15 +69,7 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
final String type = src.getString(PROP_SRC_TYPE);
final boolean isNetwork = src.getBoolean(PROP_SRC_IS_NETWORK);
videoView.reset();
if (isNetwork) {
videoView.setDataSource(uriString);
} else {
Context context = videoView.getContext();
videoView.setRawData(context.getResources().getIdentifier(uriString, "raw", context.getPackageName()));
}
// TODO: Carry this inside videoView.setSrc
WritableMap writableSrc = Arguments.createMap();
writableSrc.putString(PROP_SRC_URI, uriString);
writableSrc.putString(PROP_SRC_TYPE, type);
@ -87,8 +78,10 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
event.putMap(PROP_SRC, writableSrc);
eventEmitter.receiveEvent(videoView.getId(), Events.EVENT_LOAD_START.toString(), event);
videoView.prepare();
videoView.setSrc(uriString, isNetwork);
} catch (Exception e) {
// TODO: Send onError
// TODO: Carry inside videoView.setSrc
e.printStackTrace();
}
}