Now Android officially upgraded Exoplayer again and incorporated it into Jetpack's Media3 third-generation media library as a unified processing engine for audio and video related operations. The upgraded Exoplayer becomes the unified media playback engine of Media3, providing application-level components for audio and video playback, intending to unify the world in the direction of audio and video rendering.
According to the Android official website, ExoPlayer also gets rid of device and OS fragmentation issues, allowing app code to run in a consistent way across the Android ecosystem. Because Media3 is a very, very new Jetpack library, it requires a relatively high development environment, and the following conditions need to be met in order to properly introduce Media3.
1, development tools to choose Android Studio Jellyfish (small jellyfish version) or higher.
2. Gradle version is not less than 8.6.
3. Inside the App module, compileSdk and targetSdk should be upgraded to version 34 or higher.
After you have prepared the development environment according to the above conditions, you can introduce Media3's ExoPlayer library as described below, and the detailed steps are described as follows.
I. Modification of the module
Inside the dependencies node, add the following package-guide statement to add all the relevant libraries used by ExoPlayer.
II. Editing the layout file of the playback interface
Open the XML layout file for the playback interface and add the following property configuration to the root layout:
Next, add the PlayerView control node from the ExoPlayer library inside the layout, as shown in the example below:
Third, the event page code to add ExoPlayer processing code
First add the following line of code to declare the PlayerView object:
Then add the following code inside the onCreate method to get the PlayerView object and set the ExoPlayer player object to it:
Then add the following playback method to start playing the web video of the specified link.
From the above playback code, it can be seen that four playback forms of ExoPlayer are used here, which are: play HLS link, play RTMP link, play RTSP link, and play normal network video.
IV. Granting additional Internet access
Open and add the following internet permission configuration:
Finally compile and run the app, the player effect seen on the real machine is shown below.
You can see that you successfully ran Media3's ExoPlayer library and played the web video normally.
For more details on FFmpeg development see