Playing local/in-app mp4 files in a HTML5 videoplayer in a Cordova PhoneGap app on both Android 4.4 AND lower

StackOverflow https://stackoverflow.com/questions/23266043

Question

I got the video to work on Android 4.0.3 (API 15) and up using Jaeger 25's Html5Video plugin. However, With the addition of Android 4.4 and its revised Chromium-based WebView, this plugin no longer suffices, as mentioned by its awesome developer.

Now, I would much rather play these video's without any plugins anyway (which works perfectly on iOS...), so I went back to trying that. Is was hoping that this Chromium-based webview would be friendlier with basic HTML5 playback, but instead, I just get the exact same error as before: MediaPlayer(30579): Error (1,-2147483648).

I've spent hours trying several different approaches, all to no avail. I'll list a few things that I've tried below. Please, does anyone have any clues to point me in the right direction? I'm out of ideas...

Normal file reference using file:///

Code:

    <video id="whoismad" width="75%" height="75%" loop class="videoplayer">
        <source src="file:///android_asset/www/res/raw/whoismad.mp4" type="video/mp4">
    </video>

Results in:

04-24 11:24:30.111: D/HTML5VideoViewProxy(30579): handleMessage - PLAY
04-24 11:24:30.119: D/HTML5VideoInline(30579): HTML5VideoInline created
04-24 11:24:30.127: V/MediaPlayer-JNI(30579): native_setup
04-24 11:24:30.127: V/MediaPlayer(30579): constructor
04-24 11:24:30.142: V/MediaPlayer(30579): setListener
04-24 11:24:30.189: V/MediaPlayer(30579): setVideoSurfaceTexture
04-24 11:24:30.189: V/MediaPlayer-JNI(30579): reset
04-24 11:24:30.189: V/MediaPlayer(30579): reset
04-24 11:24:30.236: V/MediaPlayer(30579): setVideoSurfaceTexture
04-24 11:24:30.236: V/MediaPlayer(30579): prepareAsync
04-24 11:24:30.244: V/MediaPlayer(30579): message received msg=100, ext1=1, ext2=-2147483648

04-24 11:24:30.244: E/MediaPlayer(30579): error (1, -2147483648)

04-24 11:24:30.244: V/MediaPlayer(30579): callback application
04-24 11:24:30.244: V/MediaPlayer(30579): back from callback

04-24 11:24:30.252: E/MediaPlayer(30579): Error (1,-2147483648)

04-24 11:24:30.267: D/HTML5VideoViewProxy(30579): handleMessage - ERROR
04-24 11:24:30.267: D/CordovaWebView(30579): Hidding Custom View
04-24 11:24:30.267: D/HTML5VideoViewProxy(30579): handleMessage - ENDED
04-24 11:24:30.283: D/HTML5VideoViewProxy(30579): handleMessage - SEEK

File reference using Phonegap's Filesystem API

Code:

    <video id="whoismad" width="75%" height="75%" loop class="videoplayer">
        <source src="cdvfile://android_asset/www/res/raw/whoismad.mp4" type="video/mp4">
    </video>

Results in (contains that same MediaPlayer (1, -2147483648) error):

04-24 11:30:56.705: V/WebViewInputDispatcher(30579): blockWebkitDraw
04-24 11:30:56.705: V/WebViewInputDispatcher(30579): blockWebkitDraw lockedfalse
04-24 11:30:57.033: D/webview(30579): blockWebkitViewMessage= false
04-24 11:30:57.056: D/HTML5VideoViewProxy(30579): handleMessage - PLAY
04-24 11:30:57.064: V/MediaPlayer-JNI(30579): reset
04-24 11:30:57.064: V/MediaPlayer(30579): reset
04-24 11:30:57.064: D/HTML5VideoInline(30579): HTML5VideoInline created
04-24 11:30:57.080: V/MediaPlayer(30579): setVideoSurfaceTexture
04-24 11:30:57.080: V/MediaPlayer-JNI(30579): reset
04-24 11:30:57.080: V/MediaPlayer(30579): reset
04-24 11:30:57.080: I/MediaPlayer(30579): path is null
04-24 11:30:57.095: D/MediaPlayer(30579): setDataSource IOException happend : 
04-24 11:30:57.095: D/MediaPlayer(30579): java.io.FileNotFoundException: No content provider: cdvfile://android_asset/www/res/raw/usm.mp4
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:713)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:617)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.media.MediaPlayer.setDataSource(MediaPlayer.java:962)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.webkit.HTML5VideoView.prepareDataCommon(HTML5VideoView.java:326)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.webkit.HTML5VideoView.prepareDataAndDisplayMode(HTML5VideoView.java:363)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.webkit.HTML5VideoInline.prepareDataAndDisplayMode(HTML5VideoInline.java:72)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.webkit.HTML5VideoViewProxy$VideoPlayer.play(HTML5VideoViewProxy.java:286)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.webkit.HTML5VideoViewProxy.handleMessage(HTML5VideoViewProxy.java:462)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.os.Looper.loop(Looper.java:175)
04-24 11:30:57.095: D/MediaPlayer(30579):   at android.app.ActivityThread.main(ActivityThread.java:5279)
04-24 11:30:57.095: D/MediaPlayer(30579):   at java.lang.reflect.Method.invokeNative(Native Method)
04-24 11:30:57.095: D/MediaPlayer(30579):   at java.lang.reflect.Method.invoke(Method.java:511)
04-24 11:30:57.095: D/MediaPlayer(30579):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
04-24 11:30:57.095: D/MediaPlayer(30579):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
04-24 11:30:57.095: D/MediaPlayer(30579):   at dalvik.system.NativeStart.main(Native Method)
04-24 11:30:57.095: D/MediaPlayer(30579): Couldn't open file on client side, trying server side
04-24 11:30:57.095: V/MediaPlayer(30579): setVideoSurfaceTexture
04-24 11:30:57.103: V/MediaPlayer(30579): prepareAsync
04-24 11:30:57.103: V/MediaPlayer(30579): message received msg=100, ext1=1, ext2=-2147483648

04-24 11:30:57.103: E/MediaPlayer(30579): error (1, -2147483648)

04-24 11:30:57.103: V/MediaPlayer(30579): callback application
04-24 11:30:57.103: V/MediaPlayer(30579): back from callback

04-24 11:30:57.111: E/MediaPlayer(30579): Error (1,-2147483648)

04-24 11:30:57.142: D/HTML5VideoViewProxy(30579): handleMessage - ERROR
04-24 11:30:57.142: D/CordovaWebView(30579): Hidding Custom View
04-24 11:30:57.142: D/HTML5VideoViewProxy(30579): handleMessage - ENDED
04-24 11:30:57.158: D/HTML5VideoViewProxy(30579): handleMessage - SEEK
Was it helpful?

Solution

It looks like this is not currently possible with Cordova 3.4 when attempting to read a video file out of the application assets.

See https://issues.apache.org/jira/browse/CB-6079

It is possible to read the file if its copied to a directory outside the application assets, or the file is stored remotely. But not in the app assets folder any longer.

I have a similar issue - my application has a welcome screen with a short video explaining the application (~300k) which I cannot play out of the APK itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top