Added Android Expansion File Support (#142)
* Add Android Expansion File Support * Added notes for usage with Android Expansion file * Update README.md Added notes re: expansion file usage. * formatting issue fixes
This commit is contained in:
committed by
Matt Apperson
parent
8982843311
commit
4b8101398c
@@ -1,5 +1,6 @@
|
||||
package com.brentvatne.react;
|
||||
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
@@ -16,6 +17,10 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
|
||||
import com.yqritc.scalablevideoview.ScalableType;
|
||||
import com.yqritc.scalablevideoview.ScalableVideoView;
|
||||
|
||||
import com.android.vending.expansion.zipfile.APKExpansionSupport;
|
||||
import com.android.vending.expansion.zipfile.ZipResourceFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -86,7 +91,11 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
|
||||
private float mRate = 1.0f;
|
||||
private boolean mPlayInBackground = false;
|
||||
|
||||
private int mMainVer = 0;
|
||||
private int mPatchVer = 0;
|
||||
|
||||
private boolean mMediaPlayerValid = false; // True if mMediaPlayer is in prepared, started, paused or completed state.
|
||||
|
||||
private int mVideoDuration = 0;
|
||||
private int mVideoBufferedDuration = 0;
|
||||
private boolean isCompleted = false;
|
||||
@@ -160,11 +169,18 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
|
||||
}
|
||||
|
||||
public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset) {
|
||||
setSrc(uriString,type,isNetwork,isAsset,0,0);
|
||||
}
|
||||
|
||||
public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset, final int expansionMainVersion, final int expansionPatchVersion) {
|
||||
|
||||
mSrcUriString = uriString;
|
||||
mSrcType = type;
|
||||
mSrcIsNetwork = isNetwork;
|
||||
mSrcIsAsset = isAsset;
|
||||
mMainVer = expansionMainVersion;
|
||||
mPatchVer = expansionPatchVersion;
|
||||
|
||||
|
||||
mMediaPlayerValid = false;
|
||||
mVideoDuration = 0;
|
||||
@@ -199,11 +215,28 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
|
||||
setDataSource(uriString);
|
||||
}
|
||||
} else {
|
||||
setRawData(mThemedReactContext.getResources().getIdentifier(
|
||||
uriString,
|
||||
"raw",
|
||||
mThemedReactContext.getPackageName()
|
||||
));
|
||||
ZipResourceFile expansionFile= null;
|
||||
AssetFileDescriptor fd= null;
|
||||
if(mMainVer>0) {
|
||||
try {
|
||||
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(mThemedReactContext, mMainVer, mPatchVer);
|
||||
fd = expansionFile.getAssetFileDescriptor(uriString.replace(".mp4","") + ".mp4");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(fd==null) {
|
||||
setRawData(mThemedReactContext.getResources().getIdentifier(
|
||||
uriString,
|
||||
"raw",
|
||||
mThemedReactContext.getPackageName()
|
||||
));
|
||||
}
|
||||
else {
|
||||
setDataSource(fd.getFileDescriptor(), fd.getStartOffset(),fd.getLength());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -214,11 +247,18 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
|
||||
src.putString(ReactVideoViewManager.PROP_SRC_URI, uriString);
|
||||
src.putString(ReactVideoViewManager.PROP_SRC_TYPE, type);
|
||||
src.putBoolean(ReactVideoViewManager.PROP_SRC_IS_NETWORK, isNetwork);
|
||||
if(mMainVer>0) {
|
||||
src.putInt(ReactVideoViewManager.PROP_SRC_MAINVER, mMainVer);
|
||||
if(mPatchVer>0) {
|
||||
src.putInt(ReactVideoViewManager.PROP_SRC_PATCHVER, mPatchVer);
|
||||
}
|
||||
}
|
||||
WritableMap event = Arguments.createMap();
|
||||
event.putMap(ReactVideoViewManager.PROP_SRC, src);
|
||||
mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD_START.toString(), event);
|
||||
|
||||
prepareAsync(this);
|
||||
// not async to prevent random crashes on Android playback from local resource due to race conditions
|
||||
prepare(this);
|
||||
}
|
||||
|
||||
public void setResizeModeModifier(final ScalableType resizeMode) {
|
||||
@@ -443,7 +483,14 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
|
||||
protected void onAttachedToWindow() {
|
||||
|
||||
super.onAttachedToWindow();
|
||||
setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset);
|
||||
|
||||
if(mMainVer>0) {
|
||||
setSrc(mSrcUriString, mSrcType, mSrcIsNetwork,mSrcIsAsset,mMainVer,mPatchVer);
|
||||
}
|
||||
else {
|
||||
setSrc(mSrcUriString, mSrcType, mSrcIsNetwork,mSrcIsAsset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -22,6 +22,8 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
|
||||
public static final String PROP_SRC_URI = "uri";
|
||||
public static final String PROP_SRC_TYPE = "type";
|
||||
public static final String PROP_SRC_IS_NETWORK = "isNetwork";
|
||||
public static final String PROP_SRC_MAINVER = "mainVer";
|
||||
public static final String PROP_SRC_PATCHVER = "patchVer";
|
||||
public static final String PROP_SRC_IS_ASSET = "isAsset";
|
||||
public static final String PROP_RESIZE_MODE = "resizeMode";
|
||||
public static final String PROP_REPEAT = "repeat";
|
||||
@@ -72,12 +74,28 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
|
||||
|
||||
@ReactProp(name = PROP_SRC)
|
||||
public void setSrc(final ReactVideoView videoView, @Nullable ReadableMap src) {
|
||||
videoView.setSrc(
|
||||
src.getString(PROP_SRC_URI),
|
||||
src.getString(PROP_SRC_TYPE),
|
||||
src.getBoolean(PROP_SRC_IS_NETWORK),
|
||||
src.getBoolean(PROP_SRC_IS_ASSET)
|
||||
);
|
||||
int mainVer = src.getInt(PROP_SRC_MAINVER);
|
||||
int patchVer = src.getInt(PROP_SRC_PATCHVER);
|
||||
if(mainVer<0) { mainVer = 0; }
|
||||
if(patchVer<0) { patchVer = 0; }
|
||||
if(mainVer>0) {
|
||||
videoView.setSrc(
|
||||
src.getString(PROP_SRC_URI),
|
||||
src.getString(PROP_SRC_TYPE),
|
||||
src.getBoolean(PROP_SRC_IS_NETWORK),,
|
||||
src.getBoolean(PROP_SRC_IS_ASSET)
|
||||
mainVer,
|
||||
patchVer
|
||||
);
|
||||
}
|
||||
else {
|
||||
videoView.setSrc(
|
||||
src.getString(PROP_SRC_URI),
|
||||
src.getString(PROP_SRC_TYPE),
|
||||
src.getBoolean(PROP_SRC_IS_NETWORK),
|
||||
src.getBoolean(PROP_SRC_IS_ASSET)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_RESIZE_MODE)
|
||||
|
Reference in New Issue
Block a user