我有这个简单的 .m3u8 文件
#EXTM3U
#EXT-X-VERSION:5
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="English stereo",LANGUAGE="en"
#EXT-X-STREAM-INF:BANDWIDTH=1728000,CODECS="avc1.42c00d,mp4a.40.2",RESOLUTION=640x360,AUDIO="audio"
https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa_video_360_800000.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=628000,CODECS="avc1.42c00d,mp4a.40.2",RESOLUTION=320x180,AUDIO="audio"
https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa_video_180_250000.m3u8
使用 simpleExoplayer 我像这样加载这个流:
// 1. Create a default TrackSelector
Handler mainHandler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
// 2. Create the player
SimpleExoPlayer player =
ExoPlayerFactory.newSimpleInstance(context, trackSelector);
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,
Util.getUserAgent(context, "yourApplicationName"), bandwidthMeter);
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new HlsMediaSource.Factory(dataSourceFactory)
.createMediaSource(mp4VideoUri);
// Prepare the player with the source.
player.prepare(videoSource);
player.setPlayWhenReady(true);
但即使在高 WIFI 互联网上,它也将始终选择分辨率为 320x180 的第二轨道,并且永远不会切换到分辨率为 640x360 的更高轨道。
如果我用 maxInt 替换 DEFAULT_MAX_INITIAL_BITRATE 那么它将正确选择第一个轨道(640x360)但是如果在播放中间我切断了 wifi 让手机只使用低 3G 连接,那么它永远不会切换到第二个轨道(320x180),每次播放都会卡住
也是检查MediaCodecUtil.getDecoderInfo("video/avc", false).adaptive
,它返回 TRUE
我做错了什么?hls 在 simpleExoPlayer 中是否正常工作?