libgdx / gdx-video

A libGDX cross platform video rendering extension
Apache License 2.0
147 stars 50 forks source link

FileNotFoundException on Android #12

Closed mnn closed 4 years ago

mnn commented 8 years ago

I have a following snippet in Scala which works on desktop, but fails on Android 4.1 (Genymotion emulator):

val videoFile = Gdx.files.internal("vid/a.ogg")
println("video file exists: " + videoFile.exists())
video = VideoPlayerCreator.createVideoPlayer()
video.play(videoFile)

Log from failure (it doesn't crash the app, just skips playing the video):

  12-06 07:47:39.993    2124-2138/xxx.android I/System.out﹕ video file exists: true
  12-06 07:47:39.997    2124-2138/xxx.android W/System.err﹕ java.io.FileNotFoundException: a.ogg
  12-06 07:47:39.997    2124-2138/xxx.android W/System.err﹕ at android.content.res.AssetManager.openAssetFd(Native Method)
  12-06 07:47:39.997    2124-2138/xxx.android W/System.err﹕ at android.content.res.AssetManager.openFd(AssetManager.java:331)
  12-06 07:47:39.997    2124-2138/xxx.android W/System.err﹕ at com.badlogic.gdx.video.VideoPlayerAndroid.a(Unknown Source)
  12-06 07:47:39.997    2124-2138/xxx.android W/System.err﹕ at xxx.a.a.a(Unknown Source)
  12-06 07:47:39.997    2124-2138/xxx.android W/System.err﹕ at com.badlogic.gdx.backends.android.h.onSurfaceChanged(Unknown Source)
  12-06 07:47:39.997    2124-2138/xxx.android W/System.err﹕ at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)
  12-06 07:47:39.997    2124-2138/xxx.android W/System.err﹕ at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Notice the video file exists: true followed by java.io.FileNotFoundException: a.ogg, I'm very confused :confused:.

Could this be related?

12-06 07:47:39.961      123-123/? E/WVMExtractor﹕ Failed to open libwvm.so

Any help would be appreciated.

RBogie commented 8 years ago

It might be that your video is unsupported by the native android player. Could you try to play the video through your gallery?

mnn commented 8 years ago

Yeah, you are correct. Android can't play theora files, back to square one - finding free codec/container combination which runs on desktop and also on Android. BTW isn't somewhere a list of supported formats and codecs?

RBogie commented 8 years ago

You can find which formats android natively supports here: http://developer.android.com/guide/appendix/media-formats.html

Unfortunately, there is no easy way to support different formats in android at the moment. Though ffmpeg could be compiled for android as well, it would not be good enough for most purposes because it would not be hardware accelerated. The desktop can support videoformats different from theora. However, because of licensing, the precompiled binaries do not. If you have gone through the licenses and found a format that you can use, and that is supported by ffmpeg, you can include it in the ffmpeg compile.

In a project I worked on which used gdx-video, we used different asset packs for the different platforms, containing different videos for each platform. This made sense for quality as well.

mnn commented 8 years ago

Thanks for responding.

In a project I worked on which used gdx-video, we used different asset packs for the different platforms, containing different videos for each platform. This made sense for quality as well.

I am considering exactly what you're describing - different assets per platform. It's probably the best solution.

Aperico-com commented 8 years ago

I had this problem too and could not get it to work no matter what file format I used. I did some debugging and found that the FileHandle you give to VideoPlayerAndroid.play() does indeed exists. But when futher down in same method:

try {
                if (fHandle.type() == FileType.Classpath || (fHandle.type() == FileType.Internal && !fHandle.file().exists())) {
                    AssetManager assets = ((AndroidApplication)Gdx.app).getAssets();
                     AssetFileDescriptor descriptor = assets.openFd(fHandle.name());
                     player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());

                } else {
                     player.setDataSource(fHandle.file().getAbsolutePath());
                }
                player.setSurface(new Surface(videoTexture));
                player.prepareAsync();
          } catch (IOException e) {
                e.printStackTrace();
          }

It throws and exception saying FileNotFound...

 AssetFileDescriptor descriptor = assets.openFd(fHandle.name());
                     player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());

Is the problem since it does not consider the path only the file name. I then rearranged my assets so that the video files are in the root folder and now it works. Thought it might help someone else that can not get it to work using subfolders for their video files.

RBogie commented 8 years ago

Is the problem since it does not consider the path only the file name. I then rearranged my assets so that the video files are in the root folder and now it works.

Have you been able to change the library to consider the whole path? So using fHandle.path(), instead of .name()? If so, did it fix it? Did it break something?

I personally am very busy at the moment unfortunately, so I probably don't have time to fix this. It does look like a serious bug.

Aperico-com commented 8 years ago

Yes indeed changing AssetFileDescriptor descriptor = assets.openFd(fHandle.name()); to AssetFileDescriptor descriptor = assets.openFd(fHandle.path()); worked for using subfolders

emarichal commented 8 years ago

I have a following snippet in Java which works on desktop, but fails on Android.

FileHandle fileHandle = Gdx.files.internal("data/converted.mp4");

System.out.println("Exists?: " + fileHandle.exists());

videoPlayer.play(fileHandle);

Notice the video file exists: true followed by java.io.FileNotFoundException: converted.mp4.

I can play that video without problems using an android activity with videoView attached.

Any help would be appretiated.