libgdx/gdx-video

playing multiple simultaneous videos without scaling

jltrem opened this issue · 4 comments

I'm attempting to use gdx-video, with some modification, to show simultaneous videos at their true size. I've created a VideoPlayer for each video by providing an OrthographicCamera and Mesh. This construction does not work with the current VideoPlayerAndroid.java's player.setOnPreparedListener for a few reasons, but I've replaced the code with the following:

      player.setOnPreparedListener(new OnPreparedListener() {
            @Override public void onPrepared (MediaPlayer mp) {

                float w = mp.getVideoWidth();
                float h = mp.getVideoHeight();

                cam.viewportWidth = w;
                cam.viewportHeight = h;
                cam.position.set(w/2f, h/2f, 0);
                cam.update();

                mesh.setVertices(
                        new float[] {
                                0, 0, 0, 0, 1,
                                w, 0, 0, 1, 1,
                                w, h, 0, 1, 0,
                                0, h, 0, 0, 0
                        });

                 prepared = true;
                 if (sizeListener != null) {
                      sizeListener.onVideoSize(w, h);
                 }
                 mp.start();
            }
      });

I've loaded two videos -- 320x240 and 640x360 -- and they are rendered at the particular positions by calling Gdx.gl.glViewport(locX, locY, videoWidth, videoHeight) prior to rendering and then afterwards calling glViewport to set it back to the device extents.

A screenshot from a Galaxy Tab 2 7" is shown below. The correct outline of video placement is the 1px red border. I'm having trouble setting the camera and mesh so that the video is displayed in the correct proportion. Can you provide some guidance?

gdx-video

Does it only fail on android? It looks like something is going wrong in the internal mediaplayer of android. Since the mesh only uses a texture that is provided by the system, I can't think of any other reason that causes the wrong size combined with distortions.

Does it have the same issue on other android devices?

Thanks, @robbiedobbie. I've only been working with Android -- today was able to try it on a imx6 Sabre board. It runs almost perfectly on that. No distortions and width is perfectly scaled. However the vertical scaling stops at about 90%... so there is a strip of green at the bottom of each video.

Could this be a problem with the way the camera is configured? An issue with aspect ratio?

Personally I've only tested on my galaxy s4 with cyanogenmod. In there, the aspect ratio was no problem. However, I'm not sure whether some devices and/or firmwares have issues with this.

The only things not related to bugs in the mediaplayer that I can think of are:

  • Are the coordinates of the mesh correct to be visible in the viewport? Could you try with a normal texture instead of the video, and see whether this works fine.
  • Are the texture coordinates correct? Are they nicely from 0.0,0.0 in one corner to 1.0,1.0 in the opposite corner?

Could you try if the issue persists with the newest snapshot?