小编使用的是jiecaovideoplayer开源库, 原项目GitHub地址:https://github.com/lipangit/JieCaoVideoPlayer
1.在app的gradle文件中添加
compile 'fm.jiecao:jiecaovideoplayer:5.5'
compile 'com.github.bumptech.glide:glide:3.7.0'//根据自己的喜好,使用图片加载框架
2.在你的布局文件中添加
<fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard
android:id="@+id/videoplayer"
android:layout_width="match_parent"
android:layout_height="270dp" />
3.在你的播放页面Activity中添加(我添加在onCreate()方法当中)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
JCVideoPlayerStandard jcVideoPlayerStandard = (JCVideoPlayerStandard) findViewById(R.id.videoplayer);
jcVideoPlayerStandard.TOOL_BAR_EXIST = false;
jcVideoPlayerStandard.setUp("http://ssb-video.oss-cn-qingdao.aliyuncs.com/Video_1003_20161027140007.mp4"
, JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "播放视频的标题,可以为空");
// jcVideoPlayerStandard.loop = true;//是否循环播放
Glide.with(getApplicationContext()).load("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640")
.into(jcVideoPlayerStandard.thumbImageView);
jcVideoPlayerStandard.widthRatio = 4;//播放比例
jcVideoPlayerStandard.heightRatio = 3;
// JCVideoPlayerStandard.startFullscreen(this, JCVideoPlayerStandard.class, "http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4", "嫂子辛苦了");
//直接进入全屏
}
@Override
public void onBackPressed() {
if (JCVideoPlayer.backPress()) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
JCVideoPlayer.releaseAllVideos();
}
来点温馨提示吧:
JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL这个有很多个值,小伙伴可以自行研究它的功能。
4.在AndroidManifest.xml中添加代码
<uses-permission android:name="android.permission.INTERNET"/>
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
OK,这样就搞定了,上两张图片:
作者:来自唐朝的栗子
链接:https://www.jianshu.com/p/21db979dfb7f
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。