Android ExoPlayer可以';t播放HLS(HTTP实时流媒体)
我想使用ExoPlayer来播放HLS(HTTP直播)。 但我得到了以下错误: E/ExoPlayerImplInternal:源错误。 com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSource异常:无法连接到https://my_url/file.m3u8 下面是我的设置代码:Android ExoPlayer可以';t播放HLS(HTTP实时流媒体),android,kotlin,http-live-streaming,exoplayer,Android,Kotlin,Http Live Streaming,Exoplayer,我想使用ExoPlayer来播放HLS(HTTP直播)。 但我得到了以下错误: E/ExoPlayerImplInternal:源错误。 com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSource异常:无法连接到https://my_url/file.m3u8 下面是我的设置代码: private fun playTest() { player = ExoPlayerFactory.newSimpleI
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);
查看这篇文章