我正在尝试播放视频并希望在相机预览中显示它。视频以透明背景播放,视频控件也显示,但没有视频可见。我确实听到了正在播放的视频的声音。
这是我的代码:
// CameraSampleActivity.java, OnCreate Method
View layout_Initialization= (View)findViewById(R.id.layout_Initialization);
layout_Initialization.setVisibility(View.VISIBLE);
View custom_Video_Dialog=(View)findViewById(R.id.videoLayout);
custom_Video_Dialog.setVisibility(View.GONE);
//Code related to camera and camera preview here in the OnCreate method
// CameraSampleActivity.java This code is executed when video needs to be played
View custom_Video_Dialog=(View)findViewById(R.id.videoLayout);
custom_Video_Dialog.setVisibility(View.VISIBLE);
VideoView mVideoView = (VideoView) findViewById(R.id.myvideoview);
mVideoView.setMediaController(new MediaController(CameraSampleActivity.this));
mVideoView.setVideoURI(Uri.parse(firstVideo.getUrl()));
mVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
mVideoView.setFocusable(true);
mVideoView.requestFocus();
mVideoView.start();
}
});
// 这里是 main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/transparent"
android:orientation="vertical" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">
<FrameLayout android:layout_width="fill_parent"
android:layout_height="0px" android:layout_weight="1">
<FrameLayout android:id="@+id/cameraPreview"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
<RelativeLayout android:id="@+id/layout_Initialization"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/transparent" android:orientation="horizontal">
.................................
.................................
....................... .........
</RelativeLayout>
<RelativeLayout
android:id="@+id/videoLayout"
android:layout_width="fill_parent"
android:layout_height="280dp" >
<VideoView android:id="@+id/myvideoview"
android:layout_width="fill_parent" android:layout_height="180dp"
android:layout_alignParentTop="true" />
<Button android:id="@+id/videoListButton" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:text="List" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
我认为传递给 mediaController 的上下文不正确。请注意,如果我将 videoLayout 放在 frameLayout 之外,则视频可见但不透明。将它放在 Framelayout 中可以使我的透明度和视频显示在背面可见的相机预览中,这就是我想要的。有什么帮助吗?