调整视频以适应VideoView以适应、视频、VideoView

由网友(一个人、一座城、一世心疼)分享简介:我定位与AbsoluteLayout一个VideoView(我需要在几个地方显示到屏幕中的特定位置)。I'm positioning a VideoView with AbsoluteLayout (I need to display it on several places into the screen at s...

我定位与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

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>
阅读全文

相关推荐

最新文章