Video Playing Libraries in Android

Android is an operating system which is built on mobile phones. It’s based on the Linux kernel.

Working with video in Android is part of the application. This video comes from local storage on the internet, so loading the video into views needs to be effective. 

One of the basic tasks of every developer is to know how to play videos in the mobile application. Also, this library helps play the video with good performance. so in this article let’s discuss the top 3 video play libraries in Android.


1. ExoVideoPlayer

ExoPlayer is an application-level media player for Android. It will be provided for playing audio and video from the internet. 

Android native control does not provide Smooth streaming, Dash, or adaptive playback. Unlike the media player API, Exo player is easy to customize and also implemented in projects. Exop play also works on a list of videos. 

These are menu formats supported like MP3, AAC, etc. Typical video files will contain media in two sample formats 1. mp4, and 2. AAC, which is commonly indicated by the file extension.


Exoplayer Dependency

For using Exoplayer in the Android project add the dependency in the Gradle file. So, For adding dependency open app -> build.gradle file in the app folder in the Android project and add the following lines inside it.

Step 1: Add this line build.gradle file.

mplementation'com.google.android.exoplayer:exoplayer:2.19.1'

Step 2: Write the below code in your XML file of the project. 

<FrameLayout

        android:id="@+id/main_media_frame"

        android:layout_width="match_parent"

        android:layout_height="0dp"

        android:layout_weight="0.5"

        android:background="#000000">

       <androidx.media3.ui.PlayerView

            android:id="@+id/player_view"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:gravity="center" />

    </FrameLayout>

Step 3: Write the below code in your Java or kt file of the project. 

Initialization of  all variables in the class level

    private lateinit var exoPlayer: ExoPlayer

    private lateinit var playerView: PlayerView

    private var currentWindow = 0

    private var playbackPosition: Long = 0

    private var isFullscreen = false

    private var isPlayerPlaying = true

   create an object of media item for play video and pass this  exoplay object.

    private val mediaItem = MediaItem.Builder()

        .setUri(HLS_STATIC_URL)

        .setMimeType(MimeTypes.APPLICATION_M3U8)

        .build()

 This method initialization of exoplayer

 private fun initPlayer() {

    create object of exoplay with assigning playing  

        exoPlayer = ExoPlayer.Builder(this).build().apply {

            playWhenReady = isPlayerPlaying

            seekTo(currentWindow, playbackPosition)

            setMediaItem(mediaItem, false)

            prepare()

        }

        playerView.player = exoPlayer

    }

This method releases all objects .

    private fund releasePlayer() {

        isPlayerPlaying = exoPlayer.playWhenReady

        playbackPosition = exoPlayer.currentPosition

        currentWindow = exoPlayer.currentMediaItemIndex

        exoPlayer.release()

    }

2. MagicalExoPlayer

The Easiest Way To Play Video Using ExoPlayer In Your Android Application. Add Dependencies Into Your Gradle File, Sync Your Project And Then Just Pass Your URL or Local Video Address To The Player. MagicalExoPlayer Support MP4,HLS,DASHAndMP3.

 Step 1: Write the below code in your project level Gradle.

allprojects {

 repositories { 

maven { url 'https://jitpack.io' } } }

Glide Dependency

For using the Magical Exo player in the Android project add the dependency in the Gradle file. So, For adding dependency open app -> build.gradle file in the app folder in the Android project and add the following lines inside it.

Step 2: Add this line build.gradle file

Implementation 'com.github.HamidrezaAmz:MagicalExoPlayer:3.0.8'

 
Step 3: Write below code in your xml file of the project.

<com.potyvideo.library.AndExoPlayerView android:id="@+id/andExoPlayerView" android:layout_width="match_parent" android:layout_height="wrap_content" />

Step 4: Write the below code in your Java or kt file of the project.

@BindView(R.id.andExoPlayerView)

 AndExoPlayerView andExoPlayerView;

 

Step 5: Write the below code in your Java or kt file of the project.

andExoPlayerView.setSource("URL OR FILE ADDRESS");

www.domain.com/videoname.formate( URL OR FILE ADDRESs)

3. KingPlayer Dependency

For using kingplayer in the Android project add the dependency in the Gradle file. So, For adding dependency open app -> build.gradle file in the app folder in the Android project and add the following lines inside it.

Step 1: Sysplayer libraries used while adding this line in your project.


1.1 SysPlayer

implementation 'com.github.jenly1314.KingPlayer:king-player:1.0.0-beta1'

 
1.2 IjkPlayer

implementation 'com.github.jenly1314.KingPlayer:king-player:1.0.0-beta1'

implementation 'com.github.jenly1314.KingPlayer:ijk-player:1.0.0-beta1'

implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'

implementation 'tv.danmaku.ijk.media:ijkplayer-armv5:0.8.8' implementation 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8' implementation 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8' implementation 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8'

1.3 ExoPlayer

implementation 'com.github.jenly1314.KingPlayer:king-player:1.0.0-beta1' implementation 'com.github.jenly1314.KingPlayer:exo-player:1.0.0-beta1'

 
1.4 VlcPlayer

implementation 'com.github.jenly1314.KingPlayer:king-player:1.0.0-beta1' implementation 'com.github.jenly1314.KingPlayer:vlc-player:1.0.0-beta1'

In conclusion, by using video-playing libraries like MediaPlayer, and Exoplayer, you can add smooth and efficient video playback to your Android applications. These libraries offer a range of features and cater to different development requirements.


365Bloggy May 3, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive