android VideoView播放工程raw下的视频+全屏问题

1.VideoView播放视频的时候遇到了不能设置控件的宽高或者全屏的问题,这个时候就需要写一个类继承VideoView

import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;

public class VideoViewFullScreen extends VideoView {

	public VideoViewFullScreen(Context context) {
		super(context);
	}

	public VideoViewFullScreen(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

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

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int width = getDefaultSize(0, widthMeasureSpec);
		int height = getDefaultSize(0, heightMeasureSpec);
		setMeasuredDimension(width, height);
	}
}

然后用布局文件引用这个自定义的类

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.example.work.VideoViewFullScreen
        android:id="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>
2.接下来就是VideoView播放raw下的视频文件

package com.example.work;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class VideoViewActivity extends Activity {
	private VideoView video_view;
	private MediaController mediaController;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    //去掉通知栏
	    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
	    //去掉 标题
	    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
		super.onCreate(savedInstanceState);
		setContentView(R.layout.videoview);
		video_view=(VideoView)findViewById(R.id.video_view);
		mediaController=new MediaController(this);
		video_view.setMediaController(mediaController);
		//下面android.resource://是固定的,com.example.work是包名,R.raw.sw是你raw文件夹下的视频文件 
		video_view.setVideoURI(Uri.parse("android.resource://com.example.work/"+R.raw.sw));
		video_view.start();
	}
}


你可能感兴趣的:(android,视频,布局)