Skip to content Skip to sidebar Skip to footer

Android - Playing Mp4 In Videoview - No Video But Audio (z-order Doesn't Work)

I'm trying to do a simple test playing an MP4 in a VideoView, but I can only hear audio. I've already tried the Z-order trick as suggested in other posts, but it didn't work. TestL

Solution 1:

There are lots of factors to review.

  • If you are hearing the audio, the video is playing, but the video is not being decoded and displayed as expected.

  • Is this happening on an emulator or physical device?

    • If emulator, re-test on physical device
  • Are you using a H.264 Baseline Profile codec for encoding?

    • Different apps produce different versions of H.264, try encoding via a different app, i.e. ffmpeg
  • What Android API version?

    • Different versions support different codecs, review the Android docs
  • Implement MediaPlayer.IOnInfoListener and MediaPlayer.IOnErrorListener and review the MediaInfo and MediaError that you might be getting.

Note: I have found that Xamarin's Android Player fails on videos that play fine on Genymotion, same goes for AVD and BlueStacks. In the end, test on physical devices

Create a simple test app for testing your videos and review the OnError and OnInfo parameters.

IOnInfoListener/IOnErrorListener Example:

[Activity(Label = "DroidVideo", MainLauncher = true, Icon = "@mipmap/icon")]
publicclassMainActivity : Activity, MediaPlayer.IOnInfoListener, MediaPlayer.IOnErrorListener
{
    publicboolOnError(MediaPlayer mp, [GeneratedEnum] MediaError what, int extra)
    {
        Log.Debug("Media", what.ToString());
        returntrue;
    }

    publicboolOnInfo(MediaPlayer mp, [GeneratedEnum] MediaInfo what, int extra)
    {
        Log.Info("Media", what.ToString());
        returntrue;
    }

    protectedoverridevoidOnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.Main);

        Button button = FindViewById<Button>(Resource.Id.myButton);
        button.Click += delegate { 
            VideoView video = FindViewById<VideoView>(Resource.Id.myVideo);
            video.SetOnInfoListener(this);
            var videoUri = Android.Net.Uri.Parse("android.resource://" + Path.Combine(PackageName, "raw", Resource.Raw.pool.ToString()));
            video.SetVideoURI(videoUri);
            video.Start();
        };
    }
}

Layout for the example:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/myButton"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="@string/hello" /><VideoViewandroid:id="@+id/myVideo"android:layout_width="match_parent"android:layout_height="wrap_content"
            /></LinearLayout>

Solution 2:

You could try making the LinearLayout that is on top of the VideoView invisible when you play the movie and visible again once the video has finished.

Post a Comment for "Android - Playing Mp4 In Videoview - No Video But Audio (z-order Doesn't Work)"