Vitamio VideoView 示例
VideoView 播放本地视频
/*** 会根据视频尺寸自动缩放* 自己对VideoView设置的宽高基本不起任何作用*/public class VideoViewDemo extends Activity implements io.vov.vitamio.MediaPlayer.OnPreparedListener, OnClickListener {private EditText et_path;private Button bt_play;private VideoView mVideoView;@Overridepublic void onCreate(Bundle icicle) {super.onCreate(icicle);Vitamio.isInitialized(this);setContentView(R.layout.videoview);et_path = (EditText) findViewById(R.id.et_path);bt_play = (Button) findViewById(R.id.bt_play);mVideoView = (VideoView) findViewById(R.id.surface_view);mVideoView.setMediaController(new MediaController(this));mVideoView.setOnPreparedListener(this);bt_play.setOnClickListener(this);}@Overridepublic void onPrepared(MediaPlayer mp) {mp.setPlaybackSpeed(1.0f);}@Overridepublic void onClick(View v) {String filepath = et_path.getText().toString().trim();mVideoView.setVideoPath(Environment.getExternalStorageDirectory().getAbsolutePath() + filepath);mVideoView.requestFocus();mVideoView.start();}}<?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" ><io.vov.vitamio.widget.VideoViewandroid:id="@+id/surface_view"android:layout_width="300dp"android:layout_height="300dp"android:layout_gravity="center_horizontal" /><EditTextandroid:id="@+id/et_path"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="/a.rmvb" /><Buttonandroid:id="@+id/bt_play"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="播放本地多媒体" /></LinearLayout>
VideoView 播放网络视频、控制缩放类型
/*** 字幕,调整视频缩放类型* @author 白乾涛*/public class VideoViewSubtitle extends Activity implements OnPreparedListener, OnClickListener, OnTimedTextListener {//HTTP,无效//path= "http://www.modrails.com/videos/passenger_nginx.mov";//path= "http://wsmp32.bbc.co.uk/";//RTSP,无效//path= "http://m.livestream.com";//path= "rtsp://xgrammyawardsx.is.livestream-api.com/livestreamiphone/grammyawards";//MMS,无效//path= "mms://112.230.192.196/zb12";//path = "mms://ting.mop.com/mopradio";//组播 ,无效//path = "udp://236.1.0.1:2000";private String path = "http://dlqncdn.miaopai.com/stream/MVaux41A4lkuWloBbGUGaQ__.mp4";private String subtitle_path = "";private VideoView mVideoView;private TextView mSubtitleView;private Button btn_changeLayout;private Button bt_play1, bt_play2, bt_play3, bt_play4;private long mPosition = 0;private int mVideoLayout = 0;@Overridepublic void onCreate(Bundle icicle) {super.onCreate(icicle);Vitamio.isInitialized(getApplicationContext());setContentView(R.layout.subtitle2);mVideoView = (VideoView) findViewById(R.id.surface_view);btn_changeLayout = (Button) findViewById(R.id.btn_changeLayout);bt_play1 = (Button) findViewById(R.id.bt_play1);bt_play2 = (Button) findViewById(R.id.bt_play2);bt_play3 = (Button) findViewById(R.id.bt_play3);bt_play4 = (Button) findViewById(R.id.bt_play4);btn_changeLayout.setOnClickListener(this);bt_play1.setOnClickListener(this);bt_play2.setOnClickListener(this);bt_play3.setOnClickListener(this);bt_play4.setOnClickListener(this);mVideoView.setVideoPath(path);mVideoView.setMediaController(new MediaController(this));mVideoView.requestFocus();mVideoView.setOnPreparedListener(this);mVideoView.setOnTimedTextListener(this);}@Overrideprotected void onPause() {mPosition = mVideoView.getCurrentPosition();mVideoView.stopPlayback();super.onPause();}@Overrideprotected void onResume() {if (mPosition > 0) {mVideoView.seekTo(mPosition);mPosition = 0;}super.onResume();mVideoView.start();}@Overridepublic void onPrepared(MediaPlayer mp) {mp.setPlaybackSpeed(1.0f);mVideoView.addTimedTextSource(subtitle_path);//不知道哪来的APImVideoView.setTimedTextShown(true);//不知道哪来的API}@Overridepublic void onClick(View v) {if (v.getId() == R.id.btn_changeLayout) {changeLayout(v);} else {switch (v.getId()) {case R.id.bt_play1:path = "http://112.253.22.157/17/z/z/y/u/zzyuasjwufnqerzvyxgkuigrkcatxr/hc.yinyuetai.com /D046015255134077DDB3ACA0D7E68D45.flv";break;case R.id.bt_play2://HLS m3u8path = "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";break;case R.id.bt_play3:path = "http://7xt0mj.com1.z0.glb.clouddn.com/xia.v.1280.720.f4v";break;case R.id.bt_play4:path = "http://7xt0mj.com1.z0.glb.clouddn.com/lianaidaren.v.640.480.mp4";break;}mVideoView.setVideoPath(path);mVideoView.requestFocus();mVideoView.start();}}@Overridepublic void onTimedText(String text) {mSubtitleView.setText(text);}@Overridepublic void onTimedTextUpdate(byte[] pixels, int width, int height) {}public void changeLayout(View view) {mVideoLayout++;if (mVideoLayout == 4) mVideoLayout = 0;//循环switch (mVideoLayout) {case 0:mVideoLayout = VideoView.VIDEO_LAYOUT_ORIGIN;//原始画面view.setBackgroundResource(R.drawable.mediacontroller_sreen_size_100);break;case 1:mVideoLayout = VideoView.VIDEO_LAYOUT_SCALE;//全屏view.setBackgroundResource(R.drawable.mediacontroller_screen_fit);break;case 2:mVideoLayout = VideoView.VIDEO_LAYOUT_STRETCH;//拉伸view.setBackgroundResource(R.drawable.mediacontroller_screen_size);break;case 3:mVideoLayout = VideoView.VIDEO_LAYOUT_ZOOM;//裁剪view.setBackgroundResource(R.drawable.mediacontroller_sreen_size_crop);break;}mVideoView.setVideoLayout(mVideoLayout, 0);//第二个参数为【宽高比】,为0将自动检测}}<?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" ><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="400dp"android:layout_gravity="center_horizontal"android:orientation="vertical" ><io.vov.vitamio.widget.CenterLayoutandroid:id="@+id/dd"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><io.vov.vitamio.widget.VideoViewandroid:id="@+id/surface_view"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_centerHorizontal="true"android:layout_centerVertical="true" /></io.vov.vitamio.widget.CenterLayout><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:text="@string/res_audio" /></RelativeLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal" ><Buttonandroid:id="@+id/bt_play1"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="flv" /><Buttonandroid:id="@+id/bt_play2"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="m3u8" /><Buttonandroid:id="@+id/bt_play3"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="f4v" /><Buttonandroid:id="@+id/bt_play4"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="mp4" /><Buttonandroid:id="@+id/btn_changeLayout"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/mediacontroller_sreen_size_100" /></LinearLayout></LinearLayout>
VideoView 显示缓冲信息
/*** 显示缓冲相关信息* @author 白乾涛*/public class VideoViewBuffer extends Activity implements OnInfoListener, OnBufferingUpdateListener, OnPreparedListener {private String path = "http://112.253.22.157/17/z/z/y/u/zzyuasjwufnqerzvyxgkuigrkcatxr/hc.yinyuetai.com /D046015255134077DDB3ACA0D7E68D45.flv";private Uri uri;private VideoView mVideoView;private ProgressBar pb;private TextView downloadRateView, loadRateView;//网速和已经加载的百分比@Overridepublic void onCreate(Bundle icicle) {super.onCreate(icicle);Vitamio.isInitialized(getApplicationContext());setContentView(R.layout.videobuffer);mVideoView = (VideoView) findViewById(R.id.buffer);pb = (ProgressBar) findViewById(R.id.probar);downloadRateView = (TextView) findViewById(R.id.download_rate);loadRateView = (TextView) findViewById(R.id.load_rate);uri = Uri.parse(path);mVideoView.setVideoURI(uri);mVideoView.setMediaController(new MediaController(this));mVideoView.requestFocus();mVideoView.setOnInfoListener(this);mVideoView.setOnBufferingUpdateListener(this);mVideoView.setOnPreparedListener(this);}//******************************************************************************************@Overridepublic boolean onInfo(MediaPlayer mp, int what, int extra) {//在有警告或错误信息时调用。例如:开始缓冲、缓冲结束、下载速度变化switch (what) {case MediaPlayer.MEDIA_INFO_BUFFERING_START://开始缓存,暂停播放,显示正在加载if (mVideoView.isPlaying()) {mVideoView.pause();pb.setVisibility(View.VISIBLE);downloadRateView.setText("");loadRateView.setText("");downloadRateView.setVisibility(View.VISIBLE);loadRateView.setVisibility(View.VISIBLE);}break;case MediaPlayer.MEDIA_INFO_BUFFERING_END://缓存完成,继续播放mVideoView.start();pb.setVisibility(View.GONE);downloadRateView.setVisibility(View.GONE);loadRateView.setVisibility(View.GONE);break;case MediaPlayer.MEDIA_INFO_DOWNLOAD_RATE_CHANGED://显示 下载速度(KB/s)downloadRateView.setText("" + extra + "kb/s" + " ");break;}return true;}@Overridepublic void onBufferingUpdate(MediaPlayer mp, int percent) {//在网络视频流缓冲变化时调用loadRateView.setText(percent + "%");}@Overridepublic void onPrepared(MediaPlayer mp) {mp.setPlaybackSpeed(1.0f);}}<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><io.vov.vitamio.widget.CenterLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><io.vov.vitamio.widget.VideoViewandroid:id="@+id/buffer"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_centerHorizontal="true"android:layout_centerVertical="true" /></io.vov.vitamio.widget.CenterLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:orientation="horizontal" ><ProgressBarandroid:id="@+id/probar"style="?android:attr/progressBarStyleLarge"android:layout_width="wrap_content"android:layout_height="wrap_content" /><TextViewandroid:id="@+id/download_rate"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="" /><TextViewandroid:id="@+id/load_rate"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="" /></LinearLayout></RelativeLayout>
Vitamio VideoView 示例的更多相关文章
- vitamio videoView 用隐藏除videoview的控件,并旋转屏幕方向实现的全屏功能,出现的画面不能填充满videoview(画面不完整)
使用vitamio 封装的播放器 当切换到全屏模式,有时候会出现播放的画面不是全屏的情况, 全屏时,画面只占左半部分并出现拉伸效果,还显示不全,等等其他情况 阅读分析源代码发现是getHolder() ...
- 玩转Android之在线视频播放控件Vitamio的使用
其实Android中自带的MediaPlayer本身就能播放在线视频,MediaPlayer结合SurfaceView播放在线视频也是不错的选择(如果你没有性能或者用户体验上的要求),关于MediaP ...
- Android 多媒体视频播放一( 多媒体理解与经验分享)
前言 说到android的多媒体,一把辛酸一把泪,当初听说会多媒体的比较牛掰,公司也有需求,于是乎我也积极的加入研究android多媒体的行列,记得以前刚接触的时候,最开始还是比较头大的,主要是但是很 ...
- 视频播放-VideoVIew,Vitamio
播放视频文件其实并不比播放音频文件复杂,主要是使用 VideoView类来实现的.这个类将视频的显示和控制集于一身,使得我们仅仅借助它就可以完成一个简易的视频播放器.VideoView的用法和 Med ...
- Android视频媒体相关,VideoView和开源框架vitamio
虽然Android已经内置了VideoView组件和MediaPlayer类来支持开发视频播放器,但支持格式.性能等各方面都十分有限,但是Vitamio的确强大到没朋友! Vitamio 是一款 An ...
- VideoView 视频播放 示例
介绍 实现的功能: 可播放本地视频或网络视频,可控制播放或暂停 最小化时保存播放位置及播放状态,resume时恢复所有状态: 横竖屏切换时保持切换前的位置及状态 在屏幕上竖直滑动可调节屏幕亮度和音量 ...
- Vitamio
前言 虽然Android已经内置了VideoView组件和MediaPlayer类来支持开发视频播放器,但支持格式.性能等各方面都十分有限,这里与大家一起利用免费的Vitamio来打造属于自己的And ...
- vitamio框架
import io.vov.vitamio.LibsChecker; import io.vov.vitamio.MediaPlayer; import io.vov.vitamio.MediaPla ...
- Android视录视频示例
这几天需要搞一个Android视频通话功能,从最简单的视频录制开始,网上例子大多不完整.下面的示例参考过别人的代码,还是拿出来给需要的朋友分享下. Activity类:VideoActivity pa ...
随机推荐
- 【转】POJ题目分类
初级:基本算法:枚举:1753 2965贪心:1328 2109 2586构造:3295模拟:1068 2632 1573 2993 2996 图:最短路径:1860 3259 1062 2253 1 ...
- 关于ligerui和其他前端脚本的学习方法(适用于自己)
特别是看别人的源代码(来源于自己看的那个cms系统),比如ligerui,别人用的juery和ligerui结合的很灵活,比如下面一段代码 var itemiframe = "#framec ...
- Delphi-Delete 过程
过程名称 Delete 所在单元 System 过程原型 procedure Delete ( var Source : string; StartChar : Integer; Count : In ...
- Delphi-Copy 函数
函数名称 Copy 所在单元 System 函数原型 1 function Copy ( Source : string; StartChar, Count : Integer ) : string ...
- python logging模块使用
近来再弄一个小项目,已经到收尾阶段了.希望加入写log机制来增加程序出错后的判断分析.尝试使用了python logging模块. #-*- coding:utf-8 -*- import loggi ...
- Python自动化运维之17、Python操作 Memcache、Redis、RabbitMQ
一.Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的 ...
- vector list array deque
因此在实际使用时,如何选择这三个容器中哪一个,应根据你的需要而定,一般应遵循下面 的原则: 1.如果你需要高效的随即存取,而不在乎插入和删除的效率,使用vector 2.如果你需要大量的插入和 ...
- block 高级
//从后往前传值 声明block属性 //copy 目的是 将栈区的block拷贝一份到堆区 @property(nonatomic,copy)void (^sendValueBlock)(id); ...
- 倒水问题-->经典面试题目
题目详细: 有两个容器,容积分别为A升和B升,有无限多的水,现在需要C升水.我们还有一个足够大的水缸,足够容纳C升水.起初它是空的,我们只能往水缸里倒入水,而不能倒出.可以进行的操作是:把一个容器灌满 ...
- pojShredding Company
http://poj.org/problem?id=1416 #include<cstdio> #include<cstring> #define MAXN 100 using ...