1. 程式人生 > >仿今日頭條視訊播放

仿今日頭條視訊播放

轉自:https://www.jianshu.com/p/34d378bffb00

gitbug:https://github.com/lipangit/JiaoZiVideoPlayer

參考:http://blog.csdn.net/androidstarjack/article/details/69526279     注意繼承的是AppCompatActivity 否則全屏退出的時候報異常

一、專案引入:1、新增類庫
compile 'fm.jiecao:jiecaovideoplayer:4.8.3'
compile 'com.github.bumptech.glide:glide:3.7.0'

2、添加布局

 <fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard
        android:id="@+id/player_list_video"
        android:layout_width="match_parent"
        android:layout_height="220dp" />

3、下面就是我所說的通過設定視訊地址、縮圖地址、標題等幾行程式碼快速實現視訊的播放啦

 JCVideoPlayerStandard player = (JCVideoPlayerStandard) findViewById(R.id.player_list_video);
        boolean
setUp = player.setUp("http://gslb.miaopai.com/stream/ed5HCfnhovu3tyIQAiv60Q__.mp4", JCVideoPlayer.SCREEN_LAYOUT_LIST, ""); if (setUp) { Glide.with(MainActivity.this).load("http://a4.att.hudong.com/05/71/01300000057455120185716259013.jpg").into(player.thumbImageView); }

4、在Activity中

@Override
public void onBackPressed() { if (JCVideoPlayer.backPress()) { return; } super.onBackPressed(); } @Override protected void onPause() { super.onPause(); JCVideoPlayer.releaseAllVideos(); }

5、還有一點不要忘記哦,要新增許可權滴:

<!--聯網許可權-->
    <uses-permission android:name="android.permission.INTERNET" />