为 GoogleTV 盒子编写了一个播放视频的应用程序。视频是与主要活动分开的活动。在我的主布局/活动上连接一个按钮以启动视频活动(使用它自己的 video.xml 布局),视频活动加载并开始播放,但视频被剪辑,仅显示底部几厘米。剪辑区域看起来像占据先前布局 (main.xml) 的视图。有趣的是,如果我按下后退按钮,在返回主要活动之前,会显示完整的视频帧。不知道我在这里做错了什么。欢迎任何建议。
代码: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(摘录):
...
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);
}
}
视频.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(摘录)
...
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();
}
}