开源地址:https://github.com/open-android/IjkPlayer
PS:如果觉得文章太长,你也可观看该课程的视频,亲,里面还有高清,无码的福利喔
- 爱生活,爱学习,更爱做代码的搬运工,分类查找更方便请下载黑马助手app
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
compile 'com.github.open-android:IjkPlayer:1.0.0'
<com.dl7.player.media.IjkPlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="200dp"/>
mPlayerView = (IjkPlayerView) findViewById(R.id.player_view);
mUri = Uri.parse("https://covertness.qiniudn" +
".com/android_zaixianyingyinbofangqi_test_baseline.mp4");
mPlayerView.init()
.setVideoPath(mUri)
.setMediaQuality(IjkPlayerView.MEDIA_QUALITY_HIGH)
.enableDanmaku()
.start();
@Override
protected void onResume() {
super.onResume();
mPlayerView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mPlayerView.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
mPlayerView.onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mPlayerView.configurationChanged(newConfig);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (mPlayerView.handleVolumeKey(keyCode)) {
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
if (mPlayerView.onBackPressed()) {
return;
}
super.onBackPressed();
}
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
细节注意:
mPlayerView:表示视频播放的view
mUri:表示视频的路径
-
获取服务器数据推荐使用github最火开源项目RetrofitUtils.
-
详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~
-
欢迎关注微信公众号