视频视频通过相机预览



我正在尝试播放视频,并希望在相机预览中展示它。该视频具有透明背景,还显示了视频控件,但看不到视频。我确实得到了播放视频的声音。

这是我的代码:

// 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之外拍摄视频,则视频是可见的,但不透明。将其放入Framelayout中,可以使我的透明度和视频显示在背面可见的相机预览中,这是我想要的。有帮助吗?

我设法做了相似的事情,在相机视频预览中覆盖了文本视图,这可能会对您有所帮助:

与线性布局不同,声明的顺序不会在相对布局中定义z顺序。我能够通过声明这两种视图来覆盖摄像头预览的文本视图在XML中,并在我的活动的ongreate方法上以编程为编程。

假设您有一个带有文本视图的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>

如果那样留下,无论如何,相机将覆盖您的文字,:(要解决它,让我们开始编程,然后:1)将文本视图从其父级布局中分离出来2)将其连接到相机的框架布局首先连接相机。

Heres代码

oncreate(){... blaa blaaa ...

//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);

这是这样做的一般方法,如果您需要更多细节,请告诉我。我需要在工作中遇到截止日期,所以我使用第一个解决我想到的解决方案,有时不是最优雅或最有效的解决方案,如果您知道一种更好的方法,请与我们分享!

<</p>

最新更新