Running videos on android

@noel
The icon says it’s in App mode.

@akenaton gave a code with a full set of try/catch blocks. Could you post the full console error output.

@paturn @noel ===
i gave this code (tested!) for P5 IDE (dont use APDE but @noel has perhaps tested it), not for AS and Eclipse (which now is out of date for android)—For AS data folder means nothing, you have to create a folder called assets, perhaps it is the same with Eclipse…

Build folder: C:\Users\User\AppData\Local\Temp\android2659751654226666039sketch

Task :app:preBuild UP-TO-DATE
Task :app:preDebugBuild
Task :app:compileDebugAidl
Task :app:compileDebugRenderscript
Task :app:checkDebugManifest
Task :app:generateDebugBuildConfig
Task :app:prepareLintJar
Task :app:generateDebugResValues
Task :app:generateDebugResources
Task :app:mergeDebugResources
Task :app:createDebugCompatibleScreenManifests
Task :app:processDebugManifest
Task :app:splitsDiscoveryTaskDebug
Task :app:processDebugResources
Task :app:generateDebugSources
Task :app:javaPreCompileDebug
Task :app:compileDebugJavaWithJavac
Task :app:compileDebugNdk NO-SOURCE
Task :app:compileDebugSources
Task :app:mergeDebugShaders
Task :app:compileDebugShaders
Task :app:generateDebugAssets
Task :app:mergeDebugAssets
Task :app:extractTryWithResourcesSupportJarDebug
Task :app:transformClassesWithStackFramesFixerForDebug
Task :app:transformClassesWithDesugarForDebug
Task :app:transformClassesWithDexBuilderForDebug
Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug
Task :app:transformDexArchiveWithDexMergerForDebug
Task :app:mergeDebugJniLibFolders
Task :app:transformNativeLibsWithMergeJniLibsForDebug
Task :app:processDebugJavaRes NO-SOURCE
Task :app:transformResourcesWithMergeJavaResForDebug
Task :app:validateSigningDebug
Task :app:packageDebug
Task :app:assembleDebug

BUILD SUCCESSFUL in 2m 57s
28 actionable tasks: 28 executed
java.io.FileNotFoundException: ConDrift.mp4
at android.content.res.AssetManager.nativeOpenAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:899)
at processing.test.videoapp5.VideoApp5.prepareMP(VideoApp5.java:124)
at processing.test.videoapp5.VideoApp5.onStart(VideoApp5.java:174)
at processing.android.PFragment.onStart(PFragment.java:168)
at android.support.v4.app.Fragment.performStart(Fragment.java:2477)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1494)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:3235)
at android.support.v4.app.FragmentController.dispatchStart(FragmentController.java:212)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:628)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1433)
at android.app.Activity.performStart(Activity.java:7978)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3512)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2175)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7860)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
FATAL EXCEPTION: main
Process: processing.test.videoapp5, PID: 2825
java.lang.NullPointerException: Attempt to invoke virtual method ‘java.io.FileDescriptor android.content.res.AssetFileDescriptor.getFileDescriptor()’ on a null object reference
at processing.test.videoapp5.VideoApp5.prepareMP(VideoApp5.java:135)
at processing.test.videoapp5.VideoApp5.onStart(VideoApp5.java:174)
at processing.android.PFragment.onStart(PFragment.java:168)
at android.support.v4.app.Fragment.performStart(Fragment.java:2477)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1494)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:3235)
at android.support.v4.app.FragmentController.dispatchStart(FragmentController.java:212)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:628)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1433)
at android.app.Activity.performStart(Activity.java:7978)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3512)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2175)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7860)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

@noel
I have posted the erro messages but could not scroll down to indicate the receiver

@paturn === the error code is a java file not found e and that means that your video either is not in the data folder or/and the name (in the code) is not the good one…

@akenaton
The mp4 file IS in the data folder, together with many other files. I hsve emptied them out, leaving only the mp4 requested by your app. It still doesn’t work. Perhaps my settings are wrong?

@paturn === ok; are you using Eclpse or P5 ide? - Have you changed the name i put in the code for yours, “condrift.mp4” or something like that?

The ‘context’ was initiated before, so that can’t be the reason, but still, it’s strange. Are you using the internal memory or an sd card?

You can set a larger console field in the preferences.txt file (Only modify with the IDE closed!)

console.scrollback.lines=1500

Because I don’t see the print:

println(“la surface a été créé”);

@noel === as the surface is created AFTER the MP i think that the problem is the video is not found; @noel=== have you tried my code?

@akenaton
I am using Processing for Android, with ConDrift.mp4 in the data folder which is in folder
/storage/emulated/0/
or from Environment folder
/storage/emulated/0/drift

Yes, it works perfectly also without permissions.

@noel
I am using internal memory. I do not have an sdcard installed. Shall I transfer one from another phone?

Where is the sketchbook folder?

@paturn ====ok; have you changed my video name??? @noel permissions are not needed for this case, but why not?

@noel
On the PC the sketch folder is in folder Desktop\Processing P3D[app name]

On the phone the data folder is in
/storage/emulated/0/

So now I am confused.Are you building the app from the PC or APDE? From PC you don’t get a data folder, and can’t see (easily) the assets folder on your phone.

@paturn === and have you changed the name in the code?

@noel
I am building the app on the PC. APDE didn’t work either so I reverted. The folder is located with
import Environment;
pathstr = Environment.getExternalStorageDirectory()+ “/drift/”;
afd = context.getAssets().openFd(pathstr+“ConDrift.mp4”);

This technique worked in a previous app but I was not using video files, only image files with PImage

So it isn’t in the data folder!
And thus you don’t need to access the assets folder but something like:

String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+drift+"/");

In this case, you’ll need the imports and I believe on some devices you need to include

android:requestLegacyExternalStorage=“true”

to the manifest.