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.
TestLayout.axml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/testLayout"
android:clipChildren="false">
<VideoView
android:id="@+id/testVideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="10dp"
android:paddingRight="20dp"
android:paddingTop="170dp"
android:paddingBottom="100dp"
android:clipChildren="false"
android:clipToPadding="false">
<ImageButton
android:id="@+id/play"
android:layout_height="20dp"
android:layout_width="60dp"
android:background="@android:color/transparent"
android:adjustViewBounds="false"
android:src="@drawable/play"
android:scaleType="fitXY"
android:padding="0dp"/>
</LinearLayout>
</RelativeLayout>
TestActivity.cs (button trigger code):
var videoView = (VideoView)FindViewById(Resource.Id.testVideo);
videoView.SetVideoURI(Android.Net.Uri.Parse("android.resource://" + PackageName + "/" +Resource.Raw.testVideo));
videoView.SetMediaController(null);
videoView.RequestFocus();
ISurfaceHolder holder = videoView.Holder;
holder.SetType(SurfaceType.PushBuffers);
videoView.Start();
videoView.SetZOrderMediaOverlay(true);
videoView.SetZOrderOnTop(true);
Any other suggestions?
MP4 is H.264 encoded using Photoshop and is 320×240.
2
Answers
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.
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?
Are you using a H.264 Baseline Profile codec for encoding?
ffmpeg
What Android API version?
Implement
MediaPlayer.IOnInfoListener
andMediaPlayer.IOnErrorListener
and review theMediaInfo
andMediaError
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:Layout for the example: