我正在嘗試播放視頻並希望在相機預覽中進行顯示。該視頻播放透明背景,並且還顯示視頻控制,但沒有視頻可見。我確實收到了正在播放的視頻的聲音。通過相機預覽進行視頻查看
這裏是我的代碼:
// 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不正確。請注意,如果我在frameLayout之外拍攝videoLayout,則視頻可見但不透明。將其放置在Framelayout內部可以提供透明度,並且可以在背面顯示相機預覽,這正是我想要的。任何幫助?
嗨,你能找到任何解決方案嗎? –