Ijkplayer compiles the so library and ijkplayer compiles the so library.
Introduction:
The company's current radio project is my second access to audio playback project, Android audio and video
Many playbacks are still used.MediaPlayer(Except for large and medium-sized plants), but if you have used
MediaPlayer is widely used by many developers and is recommended by Google.
UseExoPlayer... When playing online audio and video, the network is poor.
Will be loaded all the time, and then it is easy to ANR... I used to want to play the audio.
After you search for and ask others, you can find the following solutions (small workshops are impossible ):
Also write a codec Player Library ):
ExoPlayer: Demo is complicated... In addition, there are not many materials on the Internet, pass;
Vitamio: Free for your use, and free for commercial use;
Compile ffmpeg by yourself: It is very complicated to listen to, and the same Pass;
Ijkplayer: Open-source Big B station
FFmpeg-based lightweight
Android/iOS video players have a lot of online materials and are officially
There are also maintenance, although there are more than 1600 issues, and mediaplayer
For similar interfaces, the learning cost is not high. You can add them to try the water!
Finally, I decided to use ijkplayer to replace the original MediaPlayer!
1. How to Use ijkplayer
Build. gradleAdd the following reference:
Dependencies {# compile 'TV is enough for most devices. danmaku. ijk. media: ijkplayer-java: 0.8.4 'compute' TV. danmaku. ijk. media: ijkplayer-armv7a: 0.8.4 '# Other ABIs: Optional compile' TV. danmaku. ijk. media: ijkplayer-armv5: 0.8.4 'compile 'TV. danmaku. ijk. media: ijkplayer-arm64: 0.8.4 'compile 'TV. danmaku. ijk. media: ijkplayer-x86: 0.8.4 'compile 'TV. danmaku. ijk. media: ijkplayer-x86_64: 0.8.4 '# ExoPlayer as IMediaPlayer: optional, experimental compile' TV. danmaku. ijk. media: ijkplayer-exo: 0.8.4 '}
Here, let's talk about something to relieve some of your doubts:
Armv7a,Armv5,Arm64,X86,X86_64These are the corresponding CPU architecture,
Generally, preparing an armv7a is enough. If the system cannot find the CPU architecture
The corresponding so library will be searchedArmeabi, More dependent on some architectures, but a little faster,
However, this is also accompanied by an increase in the size of the apk, which requires you to weigh on your own !!!
The author has only one:Armv7aNo dissatisfaction found!
The usage method is similar to that of MediaPlayer.
I used it and found a lot on the Internet. Next, let's talk about a problem I encountered:
Ijkplayer does not support HTTPS by default.
Yes,Not SupportedIf you try to useIjkplayerThe following error is reported when you play audio starting with Https:
In addition to compiling the ijkplayer source code, there is no other choice. compiling this tool can take me
Poor, all kinds of don't understand, hit the wall, but fortunately it was successful, Shun
Record the information to facilitate the latecomer.
Are all the same ...)
2. Compile ijkplayer that supports Https
Don't ask me how to compile on Windows. Anyway, I only compile on Ubuntu and MAC!
The authorUbuntu 14.04AndMac OS 10.13All are compiled successfully,
Note the following when compiling Ubuntu:
Do not clone the project to an external hard diskFor example, my computer's GB SSD
A 1 TB mechanical hard disk was mounted, cloned to the mechanical hard disk at the beginning, and then compiled
A bunch of problems, what?Ln cannot establish a link, and the chmod command is invalid.I was not poisoned,
There is no problem with cloning to SSD. The whole process is green!
Step 1:
Install Git and yasm:
sudo apt-get install gitsudo apt-get install yasm
Step 2: Download and configure the SDK and NDK
If you do not use the sdk, you will certainly have Android. NDK is generally not downloaded by default,
We do not recommend that you use the NDK downloaded by SDK Manager here. You have tried some problems before,
The minimum NDK version supports 10e. Currently, NDK 15 is not supported!
Configure the environment variables:
Ubuntu:
Modify the settings:. BashrcFile to configure the SDK and NDK:
ThenSource. bashrc, TypeNdk-build-vCheck whether there is output
Verify that the configuration takes effect.
MAC:
Open the terminal, cd to the root directory (cd ~), Then create. Bash_profileFile:
Configure as follows:
EnterSource. bash_profile, TypeNdk-build-vVerification:
Step 3: Pull ijkplayer source code
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-androidcd ijkplayer-androidgit checkout -B latest k0.8.4
Step 4: Initialize android
./init-android.sh
Step 5: compile script configuration
It is some configuration options during automatic compilation, such as what protocols are supported and what audio and video types are supported,
The configuration file is:Config/module. sh, You can open this file to see if you like:
For example, enable and disable is used to configure the type of data to be processed.
In addition, the official website provides us with three templates:
Module-default.sh: Default value. You can use this parameter if you like more types;
Module-lite-hevc.sh: If you prefer smaller binary codecs/formats (including hevc functions)
Module-lite.sh: If you prefer a small binary Decoder/format (by default)
Anyway, the smallest volume, with the module-lite.sh on the line, the use is also very simple:
rm module.shln -s module-lite.sh module.shsource module.sh
You can also enable module. sh to modify it by yourself. For example, I only want it to support mp3,
If other formats are not supported, you can change the enable format you do not want to support to disable.
Step 6: Initialize android to support Https
cd .../init-android-openssl.sh
NOTE: If NDK or SDK cannot be found, runSource ~ /. Bash_profile
Step 7: Clear a wave
cd android/contrib./compile-openssl.sh clean./compile-ffmpeg.sh clean
Step 8: Compile openssl
./compile-openssl.sh all
Step 9: Compile ffmpeg
If you want to compile the so library of all versions, it should be all.
The CPU architecture is similar to the cpu architecture, for example:./Compile-ffmpeg.sh armv7a
Compilation must be less time-consuming than all ~
./compile-ffmpeg.sh all
Step 10: Compile ijkplayer
Add all to compile the so libraries of all architectures by default,By default, only the armv7a architecture is compiled.!
./compile-ijk.sh all
Compilation takes a long time. After compilation is successful, an ijkplayer project will be generated under the directory:
At this point, compile an ijkplayer that supports HTTPS, and then how to use it:
Another remark: I have learned a lot about compilation on the Internet, and it's all done here. I don't want to tell anyone how to use it,
At first, I thought that I only needed to put the so library under the libs of my project.
An error is reported. I'm so convinced. Let's stop writing articles !!!
The simplest way to use it is to import the project into the project as a library,
It is one more in build. gradle.Compile project (': ijkplayer '),
Then you can use it. Remember to write the following:
compile 'tv.danmaku.ijk.media:ijkplayer-java:0.8.4'compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4'
Delete these dependencies. Otherwise, it will still report that HTTPS is not supported!
Generally, it is enough to reference the project here, But pig is not a very satisfying person!
So with the following!
3. Delete irrelevant items and generate the aar dependency Library
I think there are many irrelevant things. Let's talk about the expectations of pig:
1. it is only used to play music (exo and example can be removed); 2. only the armv7a architecture is required (delete other architectures and put the so library of armv7a in ijkplayer-java); 3. at last, only one ijkplayer-java is retained and exported to ijkplayer. the aar file is used by your project;
Next, let's implement pig's expectations step by step:
Step 1: Right-click the project Open Module Settings and click the minus sign to remove ijkplayer-example
And ijkplayer-java dependencies are deleted:
Then openIjkplayer-java/src/main/, Create a libs folder,
Open at the same timeIjkplayer-armv7a/main/libs, Put the armeabi-v7a file inside
The folder is copied to the ijkplayer-java libs folder.
Then you canBesides ijkplayer-example and ijkplayer-javaAll others are deleted,
Next, modify the ijkplayer-javaBuild. gradleFile, delete the last sentence, and
Modify the version information.
Next, compile a whole project, run it, click simple, and click a song to see if it can be played,
If you can play normally, go to the next step and export the aar library.
Step 2: Compile the aar Library
This is simple. Click gradle on the right and open it one by one. Right-click "run ".
After the execution is completed, the aar file is generated in the build/outputs/aar directory.
Step 3: add the aar file to the Project
This is also very simple, directly drop it to the libs folder of the app, and thenBuild. gradle
Add dependencies, (the author directly renamed the ijkplayer-java-release.aar
Ijkplayer. aar)
implementation(name: 'ijkplayer', ext: 'aar')
Next, write a simple code for playing music in the project and try the water. click the button to play a music:
public class MusicPlayActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_music_play); Button btn = findViewById(R.id.button); btn.setOnClickListener(v -> { IjkMediaPlayer player = new IjkMediaPlayer(); player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.setScreenOnWhilePlaying(true); player.setOnPreparedListener(IMediaPlayer::start); try { player.setDataSource("https:xxxx.mp3"); player.prepareAsync(); } catch (IOException e) { e.printStackTrace(); } }); }}
If the playback is normal, it indicates that our porting is very successful. If you do not use modularity,
This is the end. If you use modularization like me, you can also play the audio.
Independent modules,App-> audio playback module-> ijkplayer. aar,
Congratulations! An error is reported directly during compilation. aar, 2333 cannot be found! To solve this problem, you must
Next, let's take a look at the following ~
4. modularization. The module cannot locate the problem using aar.
Three build. gradle files need to be modified, which are audio playing module, app, and application level in sequence.
Build. gradle of the audio playback module:
App-level build. gradle:
Application-level build. gradle
Then build a wave of projects ~