Location>code7788 >text

FFmpeg development notes (60) using the domestic ijkplayer player to watch network video

Popularity:386 ℃/2024-10-26 12:03:06
ijkplayer is a domestic player developed and open-sourced by Bilibili (B Station for short) based on FFmpeg3.4, which can run on Android and iOS systems, and supports playing both local video files and streaming links on the network.

The previous article "Linux compile ijkplayer Android platform so library" describes how to compile to get the App project required ijkplayer so file, the next step is to import the official case project to the new version of Android Studio, in order to carry out the subsequent App debugging and development work.
Here we take Android Studio Dolphin (small dolphin version) as an example to introduce how to import and use ijkplayer library in the app project, the detailed steps are as follows.

I. Modify the Gradle version of the case project

Open gradle/wrapper/ in the case study project and configure the following line

distributionUrl=https\:///distributions/gradle-2.14.

Change the configuration to the following line

distributionUrl=https\:///distributions/gradle-5.4.

That is, upgrade the Gradle version version from 2.14.1 to 5.4.1.

II. Modification of the project level

Open the project level and complete the following three changes in sequence.
1, put the following line jcenter configuration

jcenter()

Replace the repository configuration with the following

gradlePluginPortal()
google()
mavenCentral()
// The following four lines add the AliCloud repository address, which makes it easy for domestic developers to download relevant plugins
maven { url '/repository/jcenter' }
maven { url '/repository/google'}
maven { url '/repository/gradle-plugin'}
maven { url '/repository/public'}
maven { url '' }

2. Put the following lines of Gradle version information

classpath ':gradle:2.1.3'
classpath ':android-maven-gradle-plugin:1.4.1'
classpath ':gradle-bintray-plugin:1.7'

Replace the Gradle version information with the following

classpath ':gradle:3.2.0'

3, put the following lines of SDK version information

compileSdkVersion = 25
buildToolsVersion = "25.0.3"
targetSdkVersion = 25

Replace the SDK version information with the following

compileSdkVersion = 28
buildToolsVersion = "28.0.3"
targetSdkVersion = 28

III. Modification of the module level

Open each module's and complete the following three changes in turn.
1. Replace all the compiles in each module with implementation.
2. Replace all "minSdkVersion 9" with "minSdkVersion 21" in each module.
3, open ijkplayer-example module alone, first productFlavors and a few lines of all32Compile and all64Compile are commented out, and then the following configuration of the guide package

compile ':appcompat-v7:23.0.1'
compile ':preference-v7:23.0.1'
compile ':support-annotations:23.0.1'

Replace it with the following package guide configuration, that is, upgrade the support library to version 28.0.0.

implementation ':appcompat-v7:28.0.0'
implementation ':preference-v7:28.0.0'
implementation ':support-annotations:28.0.0'

Fourth, import the compiled so file

Put the three so files compiled according to "Compiling ijkplayer's Android platform so libraries for Linux" into the src/main/jniLibs/arm64-v8a directory of the ijkplayer-example module, so that Android Studio will automatically load the so files here when compiling.

V. Add playback code for live links

Open the ijkplayer-example module's and add the following playback code at the end of the onCreate method.

final Context context = this;
FrameLayout fr_body = findViewById();
LinearLayout ll_body = new LinearLayout(context);
ll_body.setOrientation();
fr_body.addView(ll_body);
final EditText et_url = new EditText(context);
et_url.setText("http://124.:8080/live/test/hls.m3u8");
ll_body.addView(et_url);
Button btn_go = new Button(context);
btn_go.setText("start playing");
btn_go.setOnClickListener(new () {
    @Override
    public void onClick(View v) {
        (context, et_url.getText().toString(), "Test Video");
    }
});
ll_body.addView(btn_go);

After the above five steps of modification, compile and run the app project of ijkplayer-example module, and see the ijkplayer playback interface on the real machine as shown in the following figure.

It can be seen that the webcast address is successfully viewed on the case app through ijkplayer.

For more details on FFmpeg development seeFFmpeg Development in Action: From Zero Basics to Short Video OnlineA book.