Android ExoPlayer 无法播放 HLS(HTTP 直播)
Posted
技术标签:
【中文标题】Android ExoPlayer 无法播放 HLS(HTTP 直播)【英文标题】:Android ExoPlayer Can't Play HLS (HTTP Live Streaming) 【发布时间】: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
提前谢谢你。
【问题讨论】:
查看这篇文章intensecoder.com/android-exoplayer-tutorial-using-kotlin 【参考方案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 流。
【讨论】:
以上是关于Android ExoPlayer 无法播放 HLS(HTTP 直播)的主要内容,如果未能解决你的问题,请参考以下文章
如何从 vimeo 帐户检索视频源以在 exoplayer android 中播放?
ExoPlayer 无法播放 Adobe 实时流编码器流式传输的音频/视频 (RTMP)