Android中Vitamio的VideoView实现网络视频在线播放
来源:互联网 发布:视频开会软件 编辑:程序博客网 时间:2024/06/09 14:37
效果图:
代码:
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;@Overridepublic void onCreate(Bundle icicle) {super.onCreate(icicle);Vitamio.isInitialized(getApplicationContext());setContentView(R.layout.videoview);playfunction();myOnClick();}@Overridepublic 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() {@Overridepublic void onPrepared(MediaPlayer mediaPlayer) {// optional need Vitamio 4.0mediaPlayer.setPlaybackSpeed(1.0f);}});}}/** * 监听 */private void myOnClick(){//设置一下监听:播放完成的监听,播放准备好的监听,播放出错的监听mVideoView.setOnPreparedListener(new OnPreparedListener() {@Overridepublic void onPrepared(MediaPlayer mp) {// TODO Auto-generated method stub//开始播放progressDialog2.dismiss();}});mVideoView.setOnCompletionListener(new OnCompletionListener() {@Overridepublic void onCompletion(MediaPlayer mp) {Toast.makeText(getApplicationContext(), "视频播放完成了", Toast.LENGTH_SHORT).show();finish();//退出播放器}});mVideoView.setOnErrorListener(new OnErrorListener() {@Overridepublic 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);}//显示界面后,展示dailogProgressDialog progressDialog2=null;@Overrideprotected 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
0 0
- Android中Vitamio的VideoView实现网络视频在线播放
- Android视频播放框架Vitamio集成及使用MediaPlayer+SurfaceView、VideoView+MediaController实现播放网络视频
- android VideoView实现视频的播放
- Android视频媒体相关,VideoView和开源框架vitamio
- Android VideoView播放网络视频
- Android VideoView播放网络视频
- 使用Vitamio打造自己的Android万能播放器(5)——在线播放(播放优酷视频)
- 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)
- 使用Vitamio打造自己的Android万能播放器(5)——在线播放(播放优酷视频)
- 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)
- 使用Vitamio打造自己的Android万能播放器(5)——在线播放(播放优酷视频)
- 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)
- 使用Vitamio打造自己的Android万能播放器(5)——在线播放(播放优酷视频)
- 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)
- 使用Vitamio打造自己的Android万能播放器(5)——在线播放(播放优酷视频)
- 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)
- Android中利用VideoView播放网络上视频的基础用法
- Android VideoView实现视频播放
- BZOJ3833: [Poi2014]Solar lamps
- 安卓ListView中使用RadioGroup进行RadioButton的单项选择
- 【js/jquery】异步请求问题
- eclipse 中java compiler level does not match the version of the installed java project face问题
- map is not in the sudoers file.This incident will be reported.的解决方法
- Android中Vitamio的VideoView实现网络视频在线播放
- 高质量C编程07-指针及链表
- Android Studio系列-签名打包
- JS常用的对象函数总结归纳
- Android中使用Handler造成内存泄露的分析和解决
- 【USACO题库】2.4.2 Overfencing穿越栅栏(搜索)
- POJ3694 Network 无向图的桥
- ORACLE函数之Replace()
- android解决genymotion模拟器无法下载虚拟机问题