【问题标题】:How can i view a video inside a videoview at some specific position?如何在某个特定位置查看视频视图中的视频?
【发布时间】:2012-09-15 23:01:05
【问题描述】:

我目前正在尝试实现一个将在特定位置显示视频的视频视图。我可以毫无问题地显示全屏视频。但是,每当我尝试在一个框架内显示该视频(例如一个小矩形)时,我只能在该视图中显示一部分视频。我无法将视频放入该视图中。

我已经在寻找很多关于在 android 中缩放视频的链接,但是我找不到任何方法来做到这一点。有关该问题的任何帮助都会有所帮助。

我使用的是我有 2 个不同的课程。其中一个是我的视频活动类,另一个是助手类:

public class VideoViewCustom extends VideoView {
    private int mForceHeight = 0;
    private int mForceWidth = 0;
    public VideoViewCustom(Context context) {
        super(context);
    }     
    public VideoViewCustom(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public VideoViewCustom(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void setDimensions(int w, int h) {
        this.mForceHeight = h;
        this.mForceWidth = w;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
         setMeasuredDimension(mForceWidth, mForceHeight);
    }
}

该课程帮助我正确设置视频视图的尺寸,但是我无法使视频适合该区域。我的意思是我无法缩放视频以适应该区域。我不知道android是否会自动缩放到给定的尺寸,但我做不到。

【问题讨论】:

  • stackoverflow.com/questions/4434027/…这个链接可能对你有用
  • 我已经看过了,但没什么区别。不知道为什么强硬
  • 我通过将我的应用程序移植到 ICS 解决了这个问题。在 ICS 中它可以正常工作。然而,当我试图用 Froyo 做到这一点时,我遇到了很多问题。如果有人也面对他们,我会检查他们。
  • 第一个问题是将不同的视频类型放入一个区域。这是因为视频播放器 android 使用。我从 android 源代码更改了我的视频播放器类型,然后 .avi、.mov 和 .mp4 开始适应指定的坐标。但是,对于 2.2 的内核版本,我不能同时播放多个视频。这就是为什么我将我的应用程序移植到 ICS 中。在 ICS 中,我可以毫无问题地同时播放多个视频。

标签: android video android-videoview


【解决方案1】:

希望对你有帮助...

public void onMeasure(int width, int height)
{
    getHolder().setFixedSize(width, height);
    forceLayout();
            setMeasuredDimension(width, height);
    invalidate();
}

...并尝试相对布局

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <VideoView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true"/>

</RelativeLayout>

【讨论】:

    【解决方案2】:

    我认为你必须创建一个 ViewGroup 来实现 onLayout() 方法。

    在这里你可以直接为每个视图调用 layout() 方法来设置视图的位置。

    例子:

    ViewGroup vg = new ViewGroup(this) {
    
        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
                int x = getMeasuredWidth();
                int y = getMeasuredHeight();
                for (int i = 0; i < vg.getChildCount(); i++) {
                    if(vg.getChildAt(i) instanceof TextView){
                        vg.getChildAt(i).layout(...);//and so on...
    
                    }
                }
            }
    };
    

    希望有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-02
      • 1970-01-01
      • 2014-11-24
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      相关资源
      最近更新 更多