GoogleTv video using VideoView is clipped, even though its in a separate layout of its own
Posted
by
MYR
on Stack Overflow
See other posts from Stack Overflow
or by MYR
Published on 2012-06-29T13:34:35Z
Indexed on
2012/06/29
21:16 UTC
Read the original article
Hit count: 270
Wrote an application for GoogleTV box to play a video. The video is a separate activity to the main activity. Wired up a button on my main layout/activity to to start the video activity up (using its own video.xml layout), the video activity loads and starts playing, but the video is clipped, only showing a few centimetres of the bottom. The clipped region looks like the views that occupied the previous layout (main.xml) . The intriguing thing is that if I push the back button, before returning to the main activity the full video frame is shown. Not sure what I am doing wrong here. Any suggestions welcome.
Code: main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/hello_message"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:gravity="center"
android:text="@string/hello_message"
android:textSize="78sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/edit_message"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="@string/edit_message" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="displayMessage"
android:text="@string/button_send" />
<Button
android:id="@+id/button_send_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="sendMesssage"
android:text="@string/button_send_a" />
</LinearLayout>
<Button
android:id="@+id/videobutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="startAVideo"
android:text="Video Player" />
</LinearLayout>
GoogleTVExActivity.java (excerpt):
...
public class GoogleTVExActivity extends Activity {
public final static String EXTRA_MESSAGE = "uk.co.bbc.googletvex.MESSAGE";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void displayMessage(View view)
{
TextView t = (TextView)findViewById(R.id.hello_message);
EditText e =(EditText) findViewById(R.id.edit_message);
t.setText(e.getText().toString());
e.setText("");
}
public void sendMesssage(View view)
{
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
public void startAVideo(View view)
{
Intent intent = new Intent(this, VideoViewActivity.class);
startActivity(intent);
}
}
video.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<VideoView
android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
VideoViewActivity.java (excerpt)
...
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class VideoViewActivity extends Activity {
String SrcPath = "rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
}
© Stack Overflow or respective owner