昨天朋友问我做个视频播放器用什么插件,我当时提供了Vitamio。他晚上测试了一下说不可以,今天我就先用Vitamio入个门,如果有时间在进行深入研究。话不多说,开始:
1,:先下载Vitamio的开发包:https://github.com/yixia/VitamioBundle
2:解压文件
3:把我们需要的文件导包
4:建立自己的项目 VitamioDemo
5:编写代码
a: 先把他自带的项目中配置文件的地方copy进我的项目中
b: 添加权限
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.lbc.vitamiodemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <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:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <!-- Don't forgot InitActivity --> <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" /> <activity android:name="com.lbc.vitamiodemo.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
c:在activity_main.xml中添加布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <io.vov.vitamio.widget.VideoView android:id="@+id/surface_view" android:layout_width="match_parent" android:layout_height="200dp" /> </LinearLayout>
d:在MainActivity.java中添加代码,其中
if (!LibsChecker.checkVitamioLibs(this)) return;
很重要
public class MainActivity extends Activity { private VideoView mVideoView; private String path = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (!LibsChecker.checkVitamioLibs(this)) return; mVideoView = (VideoView) findViewById(R.id.surface_view); path="http://live.3gv.ifeng.com/zixun.m3u8"; if (path == "") { // Tell the user to provide a media file URL/path. Toast.makeText( MainActivity.this, "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show(); return; } else { /* * Alternatively,for streaming media you can use * mVideoView.setVideoURI(Uri.parse(URLstring)); */ 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); } }); } } }
e:找一个视频的连接地址,测试 http://live.3gv.ifeng.com/zixun.m3u8
6.很重要的是要导入jar包
这种是外部导入jar包,还有一种是内部导入jar包,和那个javaweb中导入数据库驱动jar包是一样的。
测试,ok,到此结束了。欢迎大神以评论的方式指点,谢谢哦。