1、下载vitamio
https://www.vitamio.org/
https://github.com/littleMeng/video-live斗鱼直播Demo
https://github.com/xiaohaibin/VitamioDemo
2、studio导入Module
直接以module的方式引入
3、配置清单文件
1)权限设置:
<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" />
2)application配置:
<!-- 必须初始化 -->
<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" />
4、初始化布局
<RelativeLayout 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="com.dzxx.live.MainActivity">
<io.vov.vitamio.widget.VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
</RelativeLayout>
5、主页面初始化进行播放
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.videoView);
//videoView.setVideoURI(Uri.parse("rtmp://live.hkstv.hk.lxdns.com/live/hks"));//设置播放地址
videoView.setVideoPath("rtmp://live.hkstv.hk.lxdns.com/live/hks");
videoView.setMediaController(new MediaController(this));
//videoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);//高画质
//videoView.start();//开始播放
videoView.requestFocus();
//设置监听
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.setPlaybackSpeed(1.0f);
}
});
最后运行就可以进行播放,注意要等待几秒钟,视频需要缓冲一会。还有几个不错的博客
http://www.jianshu.com/p/d50a67ba253c?nomobile=yes
http://www.cnblogs.com/over140/archive/2012/07/09/2582512.html
http://blog.youkuaiyun.com/yueqinglkong/article/details/41513709