I am completely stumped on something that I thought would be the easiest thing ever. I am trying to play a video inside a frame in a relative layout.
Note that the application is meant to run on a very specific device (Archos 101 internet tab) in landscape mode, and the videos are pre-encoded with a very specific size of 480x360, which is why the layout has some fixed sizes.
Here is the layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Background -->
<ImageView
android:layout_width="980dp"
android:layout_height="568dp"
android:src="@drawable/bg_video" />
<TextView
android:id="@+id/video_headtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="73dp"
android:layout_marginLeft="255dp"
android:textColor="#FFFFFF"
android:textSize="16dp" />
<TextView
android:id="@+id/video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:layout_centerHorizontal="true"
android:layout_marginTop="112dp" />
<VideoView
android:id="@+id/video_videocontainer"
android:layout_width="480dp"
android:layout_height="360dp"
android:layout_below="@id/video_title"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I load the video using this code
player = (VideoPlayer) findViewById(R.id.video_videocontainer);
player.setVideoURI(videoUri);
The code works, but while the videoView is correctly inside the frame, the video itself plays somewhere in the top of the screen, and only part of it is shown in the VideoView.
Example of what happens here (This is only a temp video for debugging). Screenshot of the video at the same moment here.
As you can see, the VideoView only shows part of the video, filling the rest with black.
I'm pretty sure I'm missing something really simple, but I can't figure out what at all.
Thanks in advance.
EDIT : I have tried writing a VideoPlayer class that extends VideoView and overrides onMeasure like this
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
setMeasuredDimension(480, 360);
}
public void changeVideoSize()
{
getHolder().setFixedSize(480, 360);
requestLayout();
invalidate();
}
But it doesn't help a single bit.
EDIT 2 : Tried with a SurfaceView and MediaPlayer, same result. I have the feeling I haven't understood the principle of playing a video on Android. Getting quite stuck here.
EDIT 3 : I have tried on a Samsung Galaxy HD and the video shows correctly inside the frame. I wonder if this is a problem with the tablet, or with 2.2?
EDIT 4 : AVD running under 2.2 doesn't render the video properly. AVD running 4.1 does. I guess that narrows it down a tad.
I had similar problem with a video that had a high too profile for that particular device (2.1) to be handled and it worked fine for android 4.0.
Other than that, I am using SurfaceView and the trick was to add listeners to the events for the MediaPlayer (setOnVideoSizeChangedListener in particular) and the callback to the surface linked to the mediaplayer events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With