Hi All,
I am having a huge problem with the Android VideoPlayer in the sense that I cannot get the video to play in my Monogame project.
Debugging the issue came down to the fact that when calling “SetDisplay” on the Android.Media.MediaPlayer object I receive in an error (shown here as debug output)
[MediaPlayer] setVideoSurfaceTexture
[MediaPlayer] message received msg=8, ext1=0, ext2=0
[MediaPlayer] unrecognized message: (8, 0, 0)
Here’s the play sequence as debugged step by step in the Android Monogame Framework:
1) Player = new Android.Media.MediaPlayer ();
The player is successfully created.
2)
var afd = Game.Activity.Assets.OpenFd (FileName);
if (afd != null) {
Player.SetDataSource (afd.FileDescriptor, afd.StartOffset, afd.Length);
This yields:
[MediaPlayer-JNI] setDataSourceFD: fd 50
[MediaPlayer] setDataSource(50, 67011184, 15127034)
All OK here.
3) Player.Prepare ();
This yields:
[MediaPlayer] prepare
[MediaPlayer] message received msg=5, ext1=800, ext2=480
[MediaPlayer] New video size 800 x 480
[MediaPlayer] callback application
[MediaPlayer] back from callback
[MediaPlayer] message received msg=1, ext1=0, ext2=0
[MediaPlayer] prepared
All OK here as well.
4) Player.SetDisplay(((AndroidGameWindow)Game.Instance.Window).GameView.Holder);
This is where the problem is:
I receive:
[MediaPlayer] setVideoSurfaceTexture
[MediaPlayer] message received msg=8, ext1=0, ext2=0
[MediaPlayer] unrecognized message: (8, 0, 0)
I have checked all the objects in the SetDisplay’s arguments and all objects exist and are initialized correctly.
In particular, the Holder object which is a Android.Views.ISurfaceHolder represents a drawing surface with the following characteristics:
Also, the Surface is created as follows:
[MonoGame] Creating Color: 32 (8888), Depth: 24, Stencil: 0, Accum:32 (8888)
and confirmed to be created successfully by this message:
[MonoGame] MonoGameAndroidGameView Context Set
[MonoGame] Created format Index: 2099322, Color: 32 (8888), Depth: 24, Stencil: 8, Samples: 0, Accum: 32 (8888), Buffers: 0, Stereo: False
Of course that when I try to invoke the “Start” function, I get an error and no video is being played.
However, if I do “SetDisplay(null);” instead of supplying my surface, I do get to hear the soundtrack of the video (which is normal.)
Here are some things that I have tried so far:
-
Made sure that the video resolution matches the surface’s resolution.
-
Attempted all possible formats: Depth 24, Stencil 8, Depth 24, Depth 16, Default, etc.
-
Call “SetDisplay” before calling “Prepare”
-
Ensured that “Prepare” is called synchronously and only after “Prepare” completed, called “SetDisplay” as results from my previous logs that I’ve shown here.
-
Made sure that the window that created the VideoPlayer was still around when attempting to show the video
-
Validated (as shown) that the objects referenced in the call to SetDisplay, as arguments, were valid and initialized.
-
Tried with the sample video that came with one of the examples of MonoGame
-
Tried Monogame ver 3.5 as well as 3.6
… and probably some more that I forgot about.
Anyway, it is imperative for me to get the video working as it is an essential part of my project.
Please note that on iOS I do not have any problems; only the Android portion is giving me the issues mentioned in this post.
Any ideas will be very appreciated,
Thank you!