【问题标题】:Android ExoPlayer Can't Play HLS (HTTP Live Streaming)Android ExoPlayer 无法播放 HLS(HTTP 直播)
【发布时间】:2020-08-28 05:49:09
【问题描述】:

我想使用 ExoPlayer 播放 HLS(HTTP Live Streaming)。 但我收到以下错误:

E/ExoPlayerImplInternal:源错误。 com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException:无法连接到 https://my_url/file.m3u8

下面是我的设置代码:

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
    }

提前谢谢你。

【问题讨论】:

标签: android kotlin http-live-streaming exoplayer


【解决方案1】:

在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

【讨论】:

    【解决方案2】:

    这里是新手,但希望它会有所帮助。我一直在做和你一样的事情,我注意到未加密的 hls 流有效。尝试使用带有 http 的链接。只是为了检查。我无法让 Exoplayer 播放 https hls 流。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-15
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-14
      • 2016-12-15
      • 1970-01-01
      相关资源
      最近更新 更多