android VideoView播放工程raw下的视频+全屏问题
16lz
2021-01-24
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);}@Overrideprotected 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;@Overrideprotected 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(安卓)自定义ScrollView 实现拉下伸缩头部view
- Android(安卓)Tips
- Android(安卓)Toast带图标水平布局的简单实现
- android水平ProgressBar颜色设置
- Android(安卓)databinding RecycleView item 子控件点击事件
- Android:ListView优化
- android常用控件(二)
- android按屏幕大小动态确定控件位置及大小
- UI 开源代码 FileBrowserView