试水Bilibili/ijkplayer-Android-Demo

来源:互联网 发布:软件系统开发评估 编辑:程序博客网 时间:2024/06/06 06:34

http://blog.csdn.net/qduningning/article/details/52330949

对ijkplayer提供的Demo进行精简优化。ijkplayer的编译请查看上一篇LINK

官方提供的Demo的代码还是挺多的,甚至还用了otto,需要对官方的demo进行精简,去除一些用不到的代码。

首先需要的是ijkplayer-{arch},ijkplayer-Java两个库,exo是Google提供的新的播放器(介绍),这里不需要,直接砍掉。

其次是ijkplayer-example里的,我们需要的只有tv.danmaku.ijk.media.example.widget.media包下的部分类。

最后,没了。。。

新建一个工程

1.把ijkplayer-armv7a/src/main/libs下的文件拷贝到新的工程的libs下。

2.把ijkplayer-java/build/outputs/aar/ijkplayer-java-release.aar复制到新工程的libs下

3.修改APP下的build.gradle, 主要设置.so及.aar的位置:

apply plugin: 'com.android.application'android {    compileSdkVersion 24    buildToolsVersion "24.0.0"    defaultConfig {        applicationId "com.znn.ijkplayerdemo"        minSdkVersion 15        targetSdkVersion 24        versionCode 1        versionName "1.0"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }    sourceSets {        main {            jniLibs.srcDirs = ['libs']        }    }}repositories {    mavenCentral()    flatDir {        dirs 'libs' //this way we can find the .aar file in libs folder    }}dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:24.0.0'    compile(name: 'ijkplayer-java-release', ext: 'aar')}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

4.复制tv.danmaku.ijk.media.example.widget.media到新的工程,删掉一些类。

5.IjkVideoView里面还是有很多如exo等没用的东西,删删删,,,

代码太多,就不贴了,具体看最底下的源码。

6.修改activity_main.xml:

<?xml version="1.0" encoding="utf-8"?><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"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".ui.MainActivity">    <com.znn.ijkplayerdemo.widget.media.IjkVideoView        android:id="@+id/video_view"        android:layout_width="match_parent"        android:layout_height="match_parent"        /></RelativeLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

7.在MainActivity里面播放视频

public class MainActivity extends AppCompatActivity {    private IjkVideoView videoView;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        videoView = (IjkVideoView) findViewById(R.id.video_view);        videoView.setAspectRatio(IRenderView.AR_ASPECT_FIT_PARENT);        videoView.setVideoURI(Uri.parse("http://zv.3gv.ifeng.com/live/zhongwen800k.m3u8"));        videoView.start();    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

OK,完成

另外可以对一些操作进行封装,如Demo中的PlayerManager,具体看代码,,,

源码看这里

原文Link

0
0
 
 

0 0
原创粉丝点击