jgillich
jgillich

Reputation: 76209

Android failed to open file

I have a video element:

<video><source src="path/video.webm" type="video/webm"></video>

This plays on Firefox and Chrome without any problems. However, when I run in on Android (emulator 4.1) it doesn't and logcat shows me this error:

Failed to open file '/android_asset/www/path/video.webm'. (No such file or directory)

The video is included in the apk under the path assets/www/path/video.webm, which should be correct.

What could be the issue here?

Upvotes: 1

Views: 2115

Answers (2)

jgillich
jgillich

Reputation: 76209

The problem is that Cordova does not support video or audio files stored inside the app. A solution is to copy the file to the internal storage and open it from there.

Quoting from CB-6079:

The assets directory is an alias to the APK. An APK is like a JAR file, it's a special type of ZIP file that has the application's classes in it, as well as its resources and assets. For any file to be accessed from the assets, it must be decompressed. This is trivial for files that aren't video, but apparently due to the nature of video files, Android isn't able to decompress these files and play them. Therfore all video files must be stored on the real file system somewhere, and not in the APK.

Upvotes: 3

Antoine
Antoine

Reputation: 558

For Android try to use 'file:///android_asset/www/path/video.webm'

But I think this solution won't work on other platforms.

Upvotes: 0

Related Questions