我在播放流时遇到问题,这是来自 EventLogger 的数据:
D/EventLogger: tracks [eventTime=16.68, mediaPos=5.04, window=0, period=0
2020-12-15 14:26:21.803 D/EventLogger: MediaCodecVideoRenderer [
2020-12-15 14:26:21.803 D/EventLogger: Group:0, adaptive_supported=N/A [
2020-12-15 14:26:21.804 D/EventLogger: [X] Track:0, id=0, mimeType=video/avc, bitrate=1470000, codecs=avc1.4D401E, res=720x576, fps=25.0, supported=YES
2020-12-15 14:26:21.804 D/EventLogger: ]
2020-12-15 14:26:21.804 D/EventLogger: Metadata [
2020-12-15 14:26:21.804 D/EventLogger: HlsTrackMetadataEntry
2020-12-15 14:26:21.804 D/EventLogger: ]
2020-12-15 14:26:21.804 D/EventLogger: ]
2020-12-15 14:26:21.804 D/EventLogger: FfmpegAudioRenderer [
2020-12-15 14:26:21.804 D/EventLogger: Group:0, adaptive_supported=N/A [
2020-12-15 14:26:21.804 D/EventLogger: [X] Track:0, id=6128/4, mimeType=audio/mpeg-L2, channels=2, sample_rate=48000, language=srb, supported=YES
2020-12-15 14:26:21.804 D/EventLogger: ]
2020-12-15 14:26:21.804 D/EventLogger: ]
2020-12-15 14:26:21.804 D/EventLogger: MediaCodecAudioRenderer []
2020-12-15 14:26:21.804 D/EventLogger: TextRenderer []
2020-12-15 14:26:21.804 D/EventLogger: MetadataRenderer [
2020-12-15 14:26:21.804 D/EventLogger: Group:0, adaptive_supported=N/A [
2020-12-15 14:26:21.804 D/EventLogger: [X] Track:0, id=null, mimeType=application/id3, supported=YES
2020-12-15 14:26:21.804 D/EventLogger: ]
2020-12-15 14:26:21.804 D/EventLogger: ]
2020-12-15 14:26:21.804 D/EventLogger: CameraMotionRenderer []
2020-12-15 14:26:21.804 D/EventLogger: ]
2020-12-15 14:26:21.808 D/EventLogger: downstreamFormat [eventTime=16.69, mediaPos=5.04, window=0, period=0, id=0, mimeType=null, bitrate=1470000, res=1048x576, fps=25.0]
2020-12-15 14:26:21.808 D/EventLogger: videoInputFormat [eventTime=16.69, mediaPos=5.04, window=0, period=0, id=0, mimeType=video/avc, bitrate=1470000, codecs=avc1.4D401E, res=720x576, fps=25.0]
2020-12-15 14:26:21.823 D/EventLogger: audioDecoderInitialized [eventTime=16.70, mediaPos=5.04, window=0, period=0, ffmpegLavc58.54.100-mp3]
2020-12-15 14:26:21.823 D/EventLogger: audioInputFormat [eventTime=16.70, mediaPos=5.04, window=0, period=0, id=6128/4, mimeType=audio/mpeg-L2, channels=2, sample_rate=48000, language=srb]
2020-12-15 14:26:21.832 D/EventLogger: audioSessionId [eventTime=16.71, mediaPos=5.04, window=0, period=0, 1857]
2020-12-15 14:26:21.997 D/EventLogger: loading [eventTime=16.88, mediaPos=5.04, window=0, period=0, false]
2020-12-15 14:26:27.782 D/EventLogger: timeline [eventTime=22.66, mediaPos=0.04, window=0, period=0, periodCount=1, windowCount=1, reason=SOURCE_UPDATE
2020-12-15 14:26:27.782 D/EventLogger: period [?]
2020-12-15 14:26:27.782 D/EventLogger: window [21.24, true, true]
2020-12-15 14:26:27.782 D/EventLogger: ]
2020-12-15 14:26:33.827 D/EventLogger: timeline [eventTime=28.71, mediaPos=-4.96, window=0, period=0, periodCount=1, windowCount=1, reason=SOURCE_UPDATE
2020-12-15 14:26:33.827 D/EventLogger: period [?]
2020-12-15 14:26:33.827 D/EventLogger: window [21.48, true, true]
2020-12-15 14:26:33.827 D/EventLogger: ]
2020-12-15 14:26:39.872 D/EventLogger: timeline [eventTime=34.75, mediaPos=-9.96, window=0, period=0, periodCount=1, windowCount=1, reason=SOURCE_UPDATE
2020-12-15 14:26:39.872 D/EventLogger: period [?]
2020-12-15 14:26:39.872 D/EventLogger: window [21.44, true, true]
2020-12-15 14:26:39.872 D/EventLogger: ]
播放器的设置方式如下:
DataSource.Factory dataSourceFactory = Tools.createDataSourceFactory(getActivity(), Util.getUserAgent(getActivity(), getActivity().getPackageName()));
DefaultRenderersFactory defaultRenderersFactory = new DefaultRenderersFactory(getActivity())
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
DefaultTrackSelector defaultTrackSelector = new DefaultTrackSelector(getActivity());
factory = new HlsMediaSource.Factory(dataSourceFactory)
.setAllowChunklessPreparation(true);
player = new SimpleExoPlayer
.Builder(getActivity(), defaultRenderersFactory)
.setTrackSelector(defaultTrackSelector)
.build();
player.addAnalyticsListener(new EventLogger(defaultTrackSelector));
binding.playerView.setPlayer(player);
public static DefaultDataSourceFactory createDataSourceFactory(Context context, String
userAgent) {
// Default parameters, except allowCrossProtocolRedirects is true
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(
userAgent,
null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
true /* allowCrossProtocolRedirects */
);
return new DefaultDataSourceFactory(
context,
null,
httpDataSourceFactory
);
}
我发现这个流与在同一播放器中工作的具有相同编解码器(avc + mpeg L2 音频)的另一个流之间的唯一区别是“mediaPos”在此流中为负值,并且逐渐减少而不是增加。
同一个流可以与 VLC 一起使用,还有另一个使用 ExoPlayer 的应用程序(我没有源代码)。
我尝试禁用 ffmpeg 扩展 - 它没有任何改变。
我使用的是ExoPlayer 2.12.2版本。
它在 ExoPlayer 演示应用程序中也不起作用。
这对我的情况有帮助
工厂 = new HlsMediaSource.Factory(dataSourceFactory) .setExtractorFactory(new DefaultHlsExtractorFactory(FLAG_ALLOW_NON_IDR_KEYFRAMES, true)) .setAllowChunklessPreparation(true);
您也可以尝试 FLAG_DETECT_ACCESS_UNITS 标志。请参阅:https://developer.android.com/media/media3/exoplayer/troubleshooting#why-do-some-mpeg-ts-files-fail-to-play