【发布时间】:2018-07-12 04:09:17
【问题描述】:
我是 Eclipse 中 android 开发的新手(因为我的电脑是低配置 PC)。 我将尝试通过网络制作像流 .m3u8 文件这样的电视应用程序。如何用 exoplayer 存档? 这让我很困惑。
【问题讨论】:
-
有点像,除了我认为提问者(可能包括我自己在内)没有意识到 m3u8 文件需要
HLS流媒体
标签: android android-layout exoplayer
我是 Eclipse 中 android 开发的新手(因为我的电脑是低配置 PC)。 我将尝试通过网络制作像流 .m3u8 文件这样的电视应用程序。如何用 exoplayer 存档? 这让我很困惑。
【问题讨论】:
HLS 流媒体
标签: android android-layout exoplayer
m3u 或 m3u8 是媒体播放列表的文件类型,仅此而已。内容格式为HLS
HLS 是:
Apple Inc 实现的基于 HTTP 的媒体流通信协议
(但非 Apple 产品可以流式传输)
这是一个教程,https://possiblemobile.com/2016/03/hls-exoplayer/ 但它是针对旧版本的 exoplayer (因为 exoplayer 最近经历了很多变化)。
这是我用来播放 m3u8 文件的工作版本(MyURL 是指向 m3u8(播放列表)文件的 http 链接:
首先启动播放器:
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoFactory);
LoadControl loadControl = new DefaultLoadControl();
// Create Player
player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl);
然后添加HlsMediaSource
Handler mHandler = new Handler();
String userAgent = Util.getUserAgent(this, "User Agent");
DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
userAgent, null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
1800000,
true);
HlsMediaSource mediaSource = new HlsMediaSource(MyURL, dataSourceFactory, 1800000,
mHandler, null);
player.setPlayWhenReady(true);
player.prepare(mediaSource);
使用 HLS,对于 m3u8 很像使用默认 MediaSource 的 exoplayer,除了你应该使用 HlsMediaSource 代替
【讨论】: