0
votes

I want to use ExoPlayer to play HLS (HTTP Live Streaming). But I got the following error:

E/ExoPlayerImplInternal: Source error. com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://my_url/file.m3u8

Below is my setup code:

private fun playTest() {
        player = ExoPlayerFactory.newSimpleInstance(
            DefaultRenderersFactory(this.requireContext()), DefaultTrackSelector(), DefaultLoadControl())
        val uri = Uri.parse("https://my_url/file.m3u8")

        ep_video_view.player = player

        val dataSourceFactory = DefaultDataSourceFactory(this.requireContext(), "user-agent")
        val mediaSource = HlsMediaSource(uri, dataSourceFactory, handler, null)

        player?.prepare(mediaSource)
        player?.playWhenReady = true
    }

Thank you in advance.

2

2 Answers

0
votes

in java

   TrackSelection.Factory adaptiveTrackSelection = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
    player = ExoPlayerFactory.newSimpleInstance(
            new DefaultRenderersFactory(mContext),
            new DefaultTrackSelector(adaptiveTrackSelection),
            new DefaultLoadControl());

    playerView.setPlayer(player);
    DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(mContext,
            Util.getUserAgent(mContext, "Exo2"), defaultBandwidthMeter);

    String hls_url = "YOUR STREAMING URL HERE";
    Uri uri = Uri.parse(hls_url);
    Handler mainHandler = new Handler();
    MediaSource mediaSource = new HlsMediaSource(uri,
            dataSourceFactory, mainHandler, null);
    player.prepare(mediaSource);
    player.setPlayWhenReady(true);

https://medium.com/@haxzie/adaptive-hls-streaming-on-android-with-googles-exoplayer-64820017edf0

0
votes

Total newbie here but hope it'll help. I've been doing the same thing as you and I noticed that unencrypted hls stream works. Try using a link with http. Just to check. I can't get Exoplayer to play https hls stream.