Android中Vitamio的VideoView实现网络视频在线播放
2016-05-13 13:20
549 查看
效果图:
代码:
1、关联Vitamio的支持库
2、布局文件videoview.xml中
3、activity中
源码及支持库下载:
http://download.csdn.net/detail/zhaihaohao1/9519049
官网
https://www.vitamio.org/docs/Tutorial/2013/0508/12.html
代码:
1、关联Vitamio的支持库
2、布局文件videoview.xml中
<span style="font-size:18px;"><?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.VideoView android:id="@+id/surface_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" /> </LinearLayout></span>
3、activity中
<span style="font-size:18px;">public class VideoViewDemo extends Activity { private VideoView mVideoView; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Vitamio.isInitialized(getApplicationContext()); setContentView(R.layout.videoview); playfunction(); myOnClick(); } @Override public void onConfigurationChanged(Configuration newConfig) { if (mVideoView != null) mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0); super.onConfigurationChanged(newConfig); } /** * 加载视频 */ void playfunction() { String path = ""; // path = "http://gslb.miaopai.com/stream/oxX3t3Vm5XPHKUeTS-zbXA__.mp4"; path = "http://gslb.miaopai.com/stream/oxX3t3Vm5XPHKUeTS-zbXA__.mp4"; mVideoView = (VideoView) findViewById(R.id.surface_view); if (path == "") { // Tell the user to provide a media file URL/path. Toast.makeText(VideoViewDemo.this, "路径错误", Toast.LENGTH_LONG) .show(); return; } else { mVideoView.setVideoPath(path); mVideoView.setMediaController(new MediaController(this)); mVideoView.requestFocus(); mVideoView .setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { // optional need Vitamio 4.0 mediaPlayer.setPlaybackSpeed(1.0f); } }); } } /** * 监听 */ private void myOnClick(){ //设置一下监听:播放完成的监听,播放准备好的监听,播放出错的监听 mVideoView.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { // TODO Auto-generated method stub //开始播放 progressDialog2.dismiss(); } }); mVideoView.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { Toast.makeText(getApplicationContext(), "视频播放完成了", Toast.LENGTH_SHORT).show(); finish();//退出播放器 } }); mVideoView.setOnErrorListener(new OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { Toast.makeText(getApplicationContext(), "视频播放出错了", Toast.LENGTH_SHORT).show(); return true; } }); /** * 缓冲设置 * */ mVideoView.setOnInfoListener(new OnInfoListener() { @Override public boolean onInfo(MediaPlayer mp, int what, int extra) { switch (what) { case MediaPlayer.MEDIA_INFO_BUFFERING_START: if (mVideoView.isPlaying()) { mVideoView.pause(); } break; case MediaPlayer.MEDIA_INFO_BUFFERING_END: mVideoView.start(); break; case MediaPlayer.MEDIA_INFO_DOWNLOAD_RATE_CHANGED: break; } return true; } }); mVideoView.setBufferSize(1024); } // 显示界面后,展示dailog ProgressDialog progressDialog2=null; @Override protected void onResume() { super.onResume(); progressDialog2=new ProgressDialog(VideoViewDemo.this); progressDialog2.setMessage("玩命加载中。。。"); progressDialog2.setCancelable(true); progressDialog2.show();//对话框显示 } }</span>4、主清单配置文件中
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.vov.vitamio.demo" android:versionCode="1" android:versionName="0.0.1" > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <application android:icon="@drawable/ic_launcher" android:label="@string/vitamio_demo_name" > <activity android:name=".VideoViewDemo" android:screenOrientation="landscape" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="io.vov.vitamio.activity.InitActivity" android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation" android:launchMode="singleTop" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden" /> </application> </manifest></span>
源码及支持库下载:
http://download.csdn.net/detail/zhaihaohao1/9519049
官网
https://www.vitamio.org/docs/Tutorial/2013/0508/12.html
相关文章推荐
- 【Unix网络编程】socket函数与描述符
- 利用response设置HTTP头
- Http Status Code(状态码)
- Unix网络编程之名字与地址转化—gethostbyname
- Http Method
- 判断网络图片是否存在
- utilities(matlab)—— 前馈网络权值矩阵初始化方式
- Http服务器状态码解析
- 网络协议
- X-Forwarded-For 负载均衡 7 层 HTTP 模式获取来访客户端真实 IP 的方法(IIS/Apache/Nginx/Tomcat)
- 简单http服务
- Jmeter TCP取样器配置及发送图解
- 利用Fiddler对Android https请求进行监测
- [转]网络诊断工具:MTR
- Android HttpURLConnection post请求
- Unity动态获取网络代码资源
- iOS网络层架构设计分享
- 网络请求
- 解决struts配置 报http status 404 错误的方案
- 基于Netty4的HttpServer和HttpClient的简单实现