Search in sources :

Example 1 with ZipResourceFile

use of com.android.vending.expansion.zipfile.ZipResourceFile in project react-native-video by react-native-community.

the class ReactVideoView method setSrc.

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;
    mVideoBufferedDuration = 0;
    initializeMediaPlayerIfNeeded();
    mMediaPlayer.reset();
    try {
        if (isNetwork) {
            // Use the shared CookieManager to access the cookies
            // set by WebViews inside the same app
            CookieManager cookieManager = CookieManager.getInstance();
            Uri parsedUrl = Uri.parse(uriString);
            Uri.Builder builtUrl = parsedUrl.buildUpon();
            String cookie = cookieManager.getCookie(builtUrl.build().toString());
            Map<String, String> headers = new HashMap<String, String>();
            if (cookie != null) {
                headers.put("Cookie", cookie);
            }
            setDataSource(mThemedReactContext, parsedUrl, headers);
        } else if (isAsset) {
            if (uriString.startsWith("content://")) {
                Uri parsedUrl = Uri.parse(uriString);
                setDataSource(mThemedReactContext, parsedUrl);
            } else {
                setDataSource(uriString);
            }
        } else {
            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) {
                int identifier = mThemedReactContext.getResources().getIdentifier(uriString, "drawable", mThemedReactContext.getPackageName());
                if (identifier == 0) {
                    identifier = mThemedReactContext.getResources().getIdentifier(uriString, "raw", mThemedReactContext.getPackageName());
                }
                setRawData(identifier);
            } else {
                setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
            }
        }
    } 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);
    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);
    // not async to prevent random crashes on Android playback from local resource due to race conditions
    try {
        prepare(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ZipResourceFile(com.android.vending.expansion.zipfile.ZipResourceFile) AssetFileDescriptor(android.content.res.AssetFileDescriptor) WritableMap(com.facebook.react.bridge.WritableMap) HashMap(java.util.HashMap) IOException(java.io.IOException) Uri(android.net.Uri) CookieManager(android.webkit.CookieManager) IOException(java.io.IOException)

Aggregations

AssetFileDescriptor (android.content.res.AssetFileDescriptor)1 Uri (android.net.Uri)1 CookieManager (android.webkit.CookieManager)1 ZipResourceFile (com.android.vending.expansion.zipfile.ZipResourceFile)1 WritableMap (com.facebook.react.bridge.WritableMap)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1