一、导入步骤:
1、上官网下载Vitamio库,下载地址:https://www.vitamio.org/
2、在eclipse中import解压好的库文件。(即将Vitamio导入到项目中)
3、在自己的项目名上右键-》Properties,点击,add按钮,将InitActivity引用到项目中。如下图示:
4、查看gen目录下是否有相应的包。(如有,则导入成功)如下图:
二、使用Vitamio库播放网络视频
1、activity_main.xml的代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<io.vov.vitamio.widget.VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="150dp" />
</RelativeLayout>
</LinearLayout>
2、MainActivity.java文件的主要代码如下:
VideoView vidView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().hide();
Vitamio.isInitialized(getApplicationContext());
setContentView(R.layout.activity_main);
vidView = (VideoView)findViewById(R.id.videoView);
vidView.setVideoURI(Uri.parse("http://cloud.video.taobao.com/play/u/2577498496/p/1/e/6/t/1/50016620184.mp4"));
MediaController mediaController=new MediaController(MainActivity.this);
vidView.setMediaController(mediaController);
vidView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.setPlaybackSpeed(1.0f);
}
});
vidView.start();
}
运行效果如下: