簡體   English   中英

Android ExoPlayer 無法播放 HLS(HTTP 直播)

[英]Android ExoPlayer Can't Play HLS (HTTP Live Streaming)

我想使用 ExoPlayer 來播放 HLS(HTTP 實時流媒體)。 但我收到以下錯誤:

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
    }

先感謝您。

在 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

這里完全是新手,但希望它會有所幫助。 我一直在做和你一樣的事情,我注意到未加密的 hls 流有效。 嘗試使用帶有 http 的鏈接。 只是為了檢查。 我無法讓 Exoplayer 播放 https hls 流。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM