Java 摄像机预览视频视图
我正在尝试播放一段视频,并希望在相机预览中显示它。视频以透明背景播放,也会显示视频控件,但看不到视频。我确实听到了正在播放的视频的声音 这是我的代码:Java 摄像机预览视频视图,java,android,video,camera,Java,Android,Video,Camera,我正在尝试播放一段视频,并希望在相机预览中显示它。视频以透明背景播放,也会显示视频控件,但看不到视频。我确实听到了正在播放的视频的声音 这是我的代码: // CameraSampleActivity.java, OnCreate Method View layout_Initialization= (View)findViewById(R.id.layout_Initialization); layout_Initialization.setVisibility(View.VISIBLE)
// 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的上下文不正确。请注意,如果我将视频布局置于框架布局之外,则视频是可见的,但不是透明的。将其放置在框架布局内,可使我的视频透明,并在背面显示摄像头预览,这正是我想要的。有什么帮助吗?我也做了类似的事情,将文本视图覆盖在摄像头视频预览上,这可能会帮助您: 与线性布局不同,声明顺序不定义相对布局中的Z顺序。 通过声明两个视图,我可以将textview覆盖在相机预览上 在XML和中,并以编程方式将它们覆盖在我的Activity的onCreate方法上 假设您有一个XML,其中包含一个文本视图,该文本视图具有一个漂亮的透明背景,您希望覆盖在相机预览帧布局上,因为为什么不呢?它看起来很酷
<RelativeLayout>
<TextView
android:id="@+id/txtnombotiga"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ola ke ase"
android:textColor="#000000"
android:textSize="16sp"
android:background="#55ffffff"
/>
<FrameLayout
android:id="@+id/cameraPreview"
android:layout_width="match_parent"
android:layout_height="240dp">
</FrameLayout>
</RelativeLayout>
这是一般的方法,如果你需要更多的细节让我知道。
我需要在工作中赶上最后期限,所以我使用我想到的第一个解决方案,有时不是最优雅或最有效的,如果你知道更好的方法,请与我们分享 嗨,你能找到解决办法吗?
//Create camera instance and reference to our frame Layout
mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
FrameLayout preview = (FrameLayout) findViewById(R.id.cameraPreview);
//Add camera to the Frame Layout
preview.addView(mPreview);
//Get reference to the TextView you want to overlay and type something funny
TextView txt=(TextView)findViewById(R.id.txtnombotiga);
txt.setText("ola keee aseee!");
//1) Step 1, here comes the magic! dettach the textView from its original Layout
((ViewGroup)txt.getParent()).removeView(txt);
//1) Step 2, voila! attach it to the View, order matters here so it will appear on
//top of the camera!
preview.addView(txt);