调整视频以适应VideoView [英] Resize video to fit the VideoView

查看:317
本文介绍了调整视频以适应VideoView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定位与AbsoluteLayout一个VideoView(我需要在几个地方显示到屏幕中的特定位置)。

I'm positioning a VideoView with AbsoluteLayout (I need to display it on several places into the screen at specific positions).

public void showVideo(RectF bounds, final String videoUrl) {
    AbsoluteLayout.LayoutParams params = (AbsoluteLayout.LayoutParams) video.getLayoutParams();
    params.width = (int) bounds.width();
    params.height = (int) bounds.height();
    params.x = (int) bounds.left;
    params.y = (int) bounds.top;

    video.requestLayout();

    video.setVisibility(View.VISIBLE);
    video.setFocusable(true);
    video.setFocusableInTouchMode(true);
    video.requestFocus();

    File file = new File(videoUrl);
    video.setVideoPath(file.getAbsolutePath());
    video.start();
}

但视频ins't越来越调整到我所指定的边界。

But the Video ins't getting resized to the bounds I specified.

任何提示?

另外一个相关的问题是,如何使的MediaController显示在VideoView?

Another related question is, how to make the MediaController show over the VideoView?

推荐答案

这是非常接近你所想。如果你愿意继承了videoview和覆盖onMeasure 这里是解决方案。你需要

this is very close to what you are trying. if you are willing to subclass the videoview and override onMeasure here is the solution. you need to

MyVideoView extends VideoView

<一个href="http://stackoverflow.com/questions/4434027/android-videoview-orientation-change-with-buffered-video/4452597#4452597">http://stackoverflow.com/questions/4434027/android-videoview-orientation-change-with-buffered-video/4452597#4452597

作为展示的MediaController超过VidowView

声明

private MediaController controller = null;

在OnCreate

OnCreate

controller = new MediaController(this);
controller.setMediaPlayer(mcEvents);
controller.setAnchorView(findViewById(R.id.wrapper));

活动

@Override
public boolean onTouchEvent(MotionEvent event) {
    //the MediaController will hide after 3 seconds - tap the screen to make it appear again
    controller.show();
    return false;
}

媒体控制器事件

Media Controller events

private MediaController.MediaPlayerControl mcEvents = new MediaController.MediaPlayerControl() {        
    public void start() {
        player.start();
    }

    public void seekTo(int pos) {
        player.seekTo(pos);         
    }

    public void pause() {
        player.pause();
    }

    public boolean isPlaying() {            
        return player.isPlaying();
    }

    public int getDuration() {          
        return player.getDuration();
    }

    public int getCurrentPosition() {           
        return player.getCurrentPosition();
    }

    public int getBufferPercentage() {          
        return pBuffer;
    }

    public boolean canSeekForward() {           
        return true;
    }

    public boolean canSeekBackward() {
        return true;
    }

    public boolean canPause() {
        return true;
    }
};

样本布局文件

a sample layout file

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.my.views.MyViedoView
    android:id="@+id/player"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
/>
</FrameLayout>

这篇关于调整视频以适应VideoView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆