Search code examples
androidhttp-live-streamingexoplayer

How to detect HLS video is for Live, VOD or Event in Exoplayer android


I have integrated android exoplayer in my application. I have to detect the HLS (.m3u8) stream received is for Live or VOD or Event, so depending on that controller has to be modified for the player. I have only one instance of player so that should handle all the supported media like vod or live or event.
I am looking for some debug points to know working of m3u8 parser in exoplayer so that I can able to receive this parameters.


Solution

  • You can use below code to play .m3u8 file:-

    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    
    //Create the player using ExoPlayerFactory
    videoPlayer = ExoPlayerFactory.newSimpleInstance(context,trackSelector);
    
    Handler mHandler = new Handler();
    
    String userAgent = Util.getUserAgent(context, "Exo Player");
    
    DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
                    userAgent, null,
                    DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                    1800000,
                    true);
    
    HlsMediaSource mediaSource = new HlsMediaSource(Uri.parse(mediaUrl),dataSourceFactory, 1800000,mHandler, null);
    
    if (mediaUrl != null) {
        videoPlayer.prepare(mediaSource);
        videoPlayer.setPlayWhenReady(true);
    }