Last active
June 19, 2019 10:25
-
-
Save gaborpapp/1b0a5d3a595126c0a3b7dac6eb8d17f6 to your computer and use it in GitHub Desktop.
Cinder Android Movie playing from file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/proj/android/libcinder_java/app/build.gradle b/proj/android/libcinder_java/app/build.gradle | |
index 8618c0e19..023d24131 100644 | |
--- a/proj/android/libcinder_java/app/build.gradle | |
+++ b/proj/android/libcinder_java/app/build.gradle | |
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 21 | |
- buildToolsVersion "21.1.2" | |
+ buildToolsVersion "28.0.3" | |
println "PROJECT DIR: ${projectDir}" | |
println "BUILD DIR : ${buildDir}" | |
diff --git a/proj/android/libcinder_java/build.gradle b/proj/android/libcinder_java/build.gradle | |
index 574631d5d..67161363f 100644 | |
--- a/proj/android/libcinder_java/build.gradle | |
+++ b/proj/android/libcinder_java/build.gradle | |
@@ -4,11 +4,11 @@ buildscript { | |
repositories { | |
jcenter() | |
flatDir { | |
- dirs "${projectDir}/../../tools/android/CinderAppBuild/repo" | |
+ dirs "${projectDir}/../../../tools/android/CinderAppBuild/repo" | |
} | |
} | |
dependencies { | |
- classpath 'com.android.tools.build:gradle:1.3.0' | |
+ classpath 'com.android.tools.build:gradle:2.3.0' | |
classpath 'org.libcinder.gradle:cinderappbuild:1.0' | |
// NOTE: Do not place your application dependencies here; they belong | |
@@ -18,6 +18,10 @@ buildscript { | |
allprojects { | |
repositories { | |
- jcenter() | |
+ mavenLocal() | |
+ jcenter() | |
+ maven { | |
+ url 'https://maven.google.com' | |
+ } | |
} | |
} | |
diff --git a/proj/android/libcinder_java/gradle/wrapper/gradle-wrapper.properties b/proj/android/libcinder_java/gradle/wrapper/gradle-wrapper.properties | |
index bf1af58e1..6ad3cae83 100644 | |
--- a/proj/android/libcinder_java/gradle/wrapper/gradle-wrapper.properties | |
+++ b/proj/android/libcinder_java/gradle/wrapper/gradle-wrapper.properties | |
@@ -4,4 +4,5 @@ distributionPath=wrapper/dists | |
zipStoreBase=GRADLE_USER_HOME | |
zipStorePath=wrapper/dists | |
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip | |
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip | |
diff --git a/proj/android/libcinder_java/libcinder/build.gradle b/proj/android/libcinder_java/libcinder/build.gradle | |
index fbbe04614..b782299f0 100644 | |
--- a/proj/android/libcinder_java/libcinder/build.gradle | |
+++ b/proj/android/libcinder_java/libcinder/build.gradle | |
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library' | |
android { | |
compileSdkVersion 22 | |
- buildToolsVersion "22.0.0" | |
+ buildToolsVersion "28.0.3" | |
defaultConfig { | |
minSdkVersion 19 | |
@@ -21,7 +21,7 @@ android { | |
sourceSets { | |
main { | |
java { | |
- srcDir "${projectDir}/../../../src/cinder/java" | |
+ srcDir "${projectDir}/../../../../src/cinder/java" | |
} | |
} | |
} | |
@@ -39,7 +39,7 @@ android { | |
if(null != srcFilePath) { | |
def srcFile = new File( srcFilePath ); | |
- def dstFile = new File( "${projectDir}/../../../lib/android/" + srcFile.getName() ) | |
+ def dstFile = new File( "${projectDir}/../../../../lib/android/" + srcFile.getName() ) | |
def srcInputStream = srcFile.newDataInputStream() | |
def srcOutputStream = dstFile.newDataOutputStream() | |
diff --git a/src/cinder/java/org/libcinder/video/VideoPlayer.java b/src/cinder/java/org/libcinder/video/VideoPlayer.java | |
index bdc817f3d..995aa9840 100644 | |
--- a/src/cinder/java/org/libcinder/video/VideoPlayer.java | |
+++ b/src/cinder/java/org/libcinder/video/VideoPlayer.java | |
@@ -2,8 +2,10 @@ package org.libcinder.video; | |
import android.content.res.AssetFileDescriptor; | |
import android.content.res.AssetManager; | |
+import android.content.Context; | |
import android.graphics.SurfaceTexture; | |
import android.media.MediaPlayer; | |
+import android.net.Uri; | |
import android.os.ConditionVariable; | |
import android.os.Handler; | |
import android.os.HandlerThread; | |
@@ -13,6 +15,7 @@ import android.view.Surface; | |
import org.libcinder.app.CinderNativeActivity; | |
+import java.io.IOException; | |
import java.net.URL; | |
import java.util.concurrent.atomic.AtomicBoolean; | |
@@ -75,10 +78,18 @@ public class VideoPlayer implements SurfaceTexture.OnFrameAvailableListener, Med | |
private void initialize(String filePath) { | |
initializeCommon(); | |
try { | |
- AssetManager am = CinderNativeActivity.getInstance().getAssets(); | |
- AssetFileDescriptor afd = am.openFd(filePath); | |
- mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); | |
+ if( filePath.startsWith("/") ) { | |
+ Context context = CinderNativeActivity.getInstance().getApplicationContext(); | |
+ mMediaPlayer.setDataSource(context, Uri.parse(filePath)); | |
+ } else { | |
+ AssetManager am = CinderNativeActivity.getInstance().getAssets(); | |
+ AssetFileDescriptor afd = am.openFd(filePath); | |
+ mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); | |
+ } | |
mMediaPlayer.prepare(); | |
+ } | |
+ catch (IOException e) { | |
+ Log.e(TAG, "IOException " + e.getMessage()); | |
} | |
catch(Exception e) { | |
Log.e(TAG, "VideoPlayer.initialize(String filePath) error: " + e.getMessage()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment