From 725bcda5c01c229557c20440b2eefe9a07e6dc2f Mon Sep 17 00:00:00 2001 From: Ralf Nieuwenhuizen Date: Thu, 13 Dec 2018 10:34:19 +0100 Subject: [PATCH] Fix export for videos over 100MB --- .../com/brentvatne/exoplayer/ExoPlayerCache.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerCache.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerCache.java index 29ae58ea88..9e97e8bd80 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerCache.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerCache.java @@ -4,6 +4,7 @@ import android.net.Uri; import android.util.Log; +import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor; import com.google.android.exoplayer2.upstream.cache.Cache; import com.google.android.exoplayer2.upstream.cache.SimpleCache; @@ -49,7 +50,7 @@ public void run() { Log.d(getName(), "Exporting..."); Log.d(getName(), url); final Uri uri = Uri.parse(url); - final DataSpec dataSpec = new DataSpec(uri, 0, 100 * 1024 * 1024, null); // TODO won't work for video's over 100 MB + final DataSpec dataSpec = new DataSpec(uri, 0, C.LENGTH_UNSET, null); final SimpleCache downloadCache = ExoPlayerCache.getInstance(getReactApplicationContext()); CacheUtil.CachingCounters counters = new CacheUtil.CachingCounters(); @@ -73,6 +74,7 @@ public void run() { try { while ((bytesRead = inputStream.read(buffer)) != -1) { outStream.write(buffer, 0, bytesRead); + // TODO Add onProgress() callback here } } catch (IOException e) { // TODO this exception should not be thrown @@ -86,8 +88,12 @@ public void run() { counters ); - // TODO are we sure the complete video is downloaded? - Log.d(getName(), "Cached " + counters.totalCachedBytes() + " bytes (end)"); + Log.d(getName(), "Cached " + counters.totalCachedBytes() + " of " + counters.contentLength + " bytes (end)"); + + // NOTE: At least 80% of the video should be cached. It looks like 100% is never achieved... + if (counters.totalCachedBytes() < counters.contentLength * .8) { + throw new Exception("Export failed - not enough content cached"); + } Log.d(getName(), "Export succeeded"); Log.d(getName(), targetFile.getPath());