00 : 00 : 00

EXOPlayer Live Streaming – Implementation and Useful Tips

Marketing & SEO
Vladislav Pshenychka 8 June, 2018
593
0

Playing music and videos with the help of live streaming is an important activity for Android devices. Consequently, there exist numerous possibilities for users to do that, most of them open source. Because of their great range, it is sometimes difficult to choose the best. Yet there exists a certain way to provide your project with the best facilities. In this article, we are going to share our opinion about what player service to choose and why. Let us introduce you to the world of unlimited streaming possibilities, where the native MediaPlayer remains one of the most popular. However, there also appeared a new field player. ExoPlayer, with its EXOPlayer live streaming has a broader scope of functions and is ready to become your next favorite.

EXOPlayer live streaming main image

Short Overview

Back in 2014, implementation of the Google ExoPlayer library for a video player with the custom control operating and ‘exo live stream’ was a brilliant idea. The built-in native MediaPlayer proved its inconsistency in such an important matter as stable and reliable behavior on different devices. Its capriciousness together with the heaviness of code and uncompromising performance policy made it notorious among the experts. On the contrary, the newly-released ExoPlayer, built on the base of Android’s low-level media APIs, ensured the best music and video streaming possibilities.

The first and foremost reason for its release was, of course, implementation of HTTP Live Streaming (HLS) – a protocol for media broadcasting developed by Apple. In it, video content consists of fragments loaded in real time and with adaptive bit transfer rate. That is how ExoPlayer live streaming became a fully customizable alternative to the native MediaPlayer APIs, providing a convenient API for streaming video and audio across all the devices. Now it is used by thousands of apps with such celebrity names as BBC included.

Alternatives (and Why You Shouldn’t Choose Them)

Of course, ExoPlayer has a number of rather successful competitors. They include such well-known services as:

vimeo exo streaming image

vitamio exoplayer hls image

However, it can be now surely stated that ExoPlayer is much better than any of them. Despite its impressive number of subscribers, Vimeo lacks flexibility, as the content is stored exclusively on its servers, with an iframe link provided for playback in WebView. That reduces the performance of the application significantly. Being based on the popular FFmpeg library and possessing lots of useful features, Vitamio gained much popularity. However, it is a non-free service, so not many people are ready to use it. LibVLC is rather restricted in its functionality, as it handles only projects with NDK support. That is why ExoPlayer is the most popular service of this type nowadays.

What Is Positive?

As any service, ExoPlayer has its advantages and drawbacks. Its main pros include:

  • implementation of exoplayer HLS with all its advanced features, such as bug handling etc.;
  • easy start;
  • Java base, which enables the possibility of successful debugging;
  • variety of formats;
  • full support of the Widevine common encryption for Android 4.4 and higher.
  • control components that are fully customizable;
  • a possibility of playing audio and video in a stream;
  • subtitle support;
  • Google Cast SDK support, which enables its working with Tv or sound system;
  • MediaSource usage.

The latter allows configuring of not only the exoplayer HLS stream, but also DASH (DashMediaSource) and SmoothStreaming (SsMediaSource). It also enables such EXOPlayer live streaming components as side-loaded subtitles, as well as playback of the video sequences. One more exciting feature it possesses is the newly released PlayerNotificationManager, which enables the user to get playback notifications to control your video or audio exo streaming. With them, you can smoothly forward, rewind, turn to the next track etc. To create MediaSource for HLS video streaming, you need to perform such simple actions:


fun getHlsMediaSource(hls: String): MediaSource {
val bandwidthMeter = DefaultBandwidthMeter()
val applicationName = Util.getUserAgent(context, APPLICATION_NAME)
val dataSourceFactory = DefaultDataSourceFactory(context, applicationName, bandwidthMeter)
val factory = HlsMediaSource.Factory(dataSourceFactory)
return factory.createMediaSource(Uri.parse(hls))
}


Moreover, the EXOPlayer live streaming library has a range of other fantastic capacities, such as MergingMediaSource, ConcatenatingMediaSource, TrackSelector, and LoopingMediaSource. They all guarantee the perfect performance of a complex system of Exo streaming possibilities. ExoPlayer has a range of these components by default for the basic functioning. However, it can also make use of numerous customized implementation for non-standard performance.

All in all, exo live stream handles all the important tasks, such as streaming video with the identification of errors associated with the source of content, adding a video or audio player that supports the bulk of modern formats to your mobile or TV application in a short time etc.

What Is Negative?

Of course, nothing is perfect. EXOPlayer live streaming, despite its modernity and a number of exciting features, is no exception to that. Its main disadvantages are as follows:

  • design limitations;
  • lack of support for earlier than 16 Android versions;
  • an impossibility of the player’s recreation performance in case of a screen lock;
  • no backwinding to the last viewed position.

The working solution for the latter challenges looks like this:


override fun onPause() {

super.onPause()

releasePlayer()

}


private fun releasePlayer() {

if (simpleExoPlayer != null) {

resumePosition = Math.max(0, simpleExoPlayer!!.contentPosition)

shouldAutoPlay = simpleExoPlayer!!.playWhenReady

       simpleExoPlayer!!.release()

simpleExoPlayer = null

   }

}


override fun onResume() {

super.onResume()

initPlayer()

}


private fun initPlayer() {

simpleExoPlayer = streamConfigurator.createExoPlayer()

simpleExoPlayerView.useController = true

   simpleExoPlayerView.player = simpleExoPlayer

simpleExoPlayer?.seekTo(resumePosition)

}


However, these problems may be attributed to the peculiarities of the Android architecture and its hyperthreading, Android developers might have a somewhat hard time. Other than that, ExoPlayer live streaming is a great choice.

Algorithm of EXOPlayer Live Streaming

Experts claim ExoPlayer to be really handy and easy to use, and we totally agree with this thought. To start your work with it, you need to perform just a few simple steps. They include:

  • adding ExoPlayer to your project in a dependency form. Adding it to the file of the app module will ensure its work for the full ExoPlayer live streaming library;
  • creating a SimpleExoPlayer instance (use ExoPlayerFactory for that);
  • attachment of the player to the view for both video output and easy user input;
  • preparation of the player’s MediaSource to play.
  • the player’s release (with a special code).

Conclusions

ExoPlayer live streaming is an open source ready-made solution that allows solving many issues problematic for other libraries. As you can see, its list of advantages and positive features is much longer than the enumeration of the negative ones. Probably due to that reason, it is used in the vast majority of Android applications and is fully supported by Google. In comparison with its main alternatives, it is much more flexible and simple. Our team advises you to start using it, as its exciting features can make a huge mash on you.

Tags: developer's guide video content video gallery video tutorials web development
Author: Vladislav Pshenychka
Vladislav Pshenychka is a brand strategist, digital marketing expert, and a blogger. He is a passionate digital strategist. Currently, associated with Artjoker - a leading web development company in Los Angeles.
Request a Callback
Our operator will contact you in
Our operator will contact you in
We can call you in 30 seconds, just enter your number below
Would you like a callback once we are back in office?
Please, enter valid phone
We can call you in 30 seconds, just enter your number below
30
No phone call?
Our manager will get in touch with you within next 24 business hours
Submit a Request
Feel free to reach our team with any concern, we will gladly assist you!