android学习之视频播放
2016-04-15 16:59
363 查看
果断这几篇文章都是写的多媒体的,这篇文章就谈谈如果使用VideoView来播放视频,其实感觉和播放音乐差不多的,直接贴代码,因为感觉也蛮简单的,对了,,在后面我继承了VideoView写了一个自己的VideoView,这样我们方便设置Video来适配自己的屏幕。
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;
public class MyVideoView extends VideoView {
// those three constructor will be use for the different way to create view
public MyVideoView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
}
public MyVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
// measure the width of the screen
int width = getDefaultSize(0, widthMeasureSpec);
// measure the height of the screen
int height = getDefaultSize(0, heightMeasureSpec);
// set the size that we use to play the video
setMeasuredDimension(width, height);
}
}
package com.example.videoviewdemo; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.MediaController; import android.widget.VideoView; public class MainActivity extends Activity { // declar a VideoView private VideoView myVideoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myVideoView = (VideoView) findViewById(R.id.my_video); // get the path String path = "/sdcard/fcar.3gp"; // set the path for VideoView myVideoView.setVideoPath(path); // Uri // MyUri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.aa); // myVideoView.setVideoURI(MyUri); // MediaController is used for us to control the progress MediaController mc = new MediaController(this); // bind the MediaController with the VideoView myVideoView.setMediaController(mc); // get the focus myVideoView.requestFocus(); // play the Video myVideoView.start(); } }package com.example.videoviewdemo;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;
public class MyVideoView extends VideoView {
// those three constructor will be use for the different way to create view
public MyVideoView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
}
public MyVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
// measure the width of the screen
int width = getDefaultSize(0, widthMeasureSpec);
// measure the height of the screen
int height = getDefaultSize(0, heightMeasureSpec);
// set the size that we use to play the video
setMeasuredDimension(width, height);
}
}
相关文章推荐
- Android 设置透明按钮
- Android 破解APK
- Android 源码5.1调用系统设置页面
- Android实用工具类-GrallyAndPhotoUtils图片处理工具
- android 根据域名得到IP
- android 获取屏幕高度和宽度
- Android 银行卡扫描识别获取卡号
- android Mediaplayer各种属性和方法简单介绍
- Android Wear 开发环境 ---- Hello World
- 各种Android控件实用
- 冒泡排序和快速排序以及Android的collections.sort排序
- Android系统图册更新保存的图片
- 问题:COMPLEX_UNIT_PX
- Android读取相册时报错:Attempted to access a cursor after it has been closed.
- Android学习----自适应国际化语言
- Android 源码5.1调用系统关机
- android studio设置注释模板
- Android系统服务接口
- 细说Android事件传递机制(dispatchTouchEvent、onInterceptTouchEvent、onTouchEvent)
- Android 文件系统 内部存储和外部存储的区别