java - Mp4 file from Url is taking too long to play
问题描述
I have a mp4 Url, which is containing 400mb of video. Using exoplayer, it's taking too long (10-15 min) for start the playing the video. I have added loadcontrol but no use. Can anybody help me ?
MediaSource videoSource = new
ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(mUri);
// Prepare the player with the source.
Log.d("exo","to be prepare");
player.prepare(videoSource);
Log.d("exo","prepared"+videoSource);
player.setPlayWhenReady(true);
Log.d("exo","played");
player.addListener(this);
============================
LoadControl loadControl = new DefaultLoadControl( new DefaultAllocator(true, 16), VideoPlayerConfig.MIN_BUFFER_DURATION, VideoPlayerConfig.MAX_BUFFER_DURATION, VideoPlayerConfig.MIN_PLAYBACK_START_BUFFER, VideoPlayerConfig.MIN_PLAYBACK_RESUME_BUFFER, -1, true);
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
// 2. Create the player
player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), trackSelector, loadControl);
videoFullScreenPlayer.setPlayer(player);
解决方案
This might have multiple causes:
1. The max buffer duration is too large
Try to play with setting a lower value for VideoPlayerConfig.MAX_BUFFER_DURATION
(which is 30 seconds
apparently)
2. Your streaming video protocol is not efficient
It possibly has to do with the video encoding in combination with your network speed limitations. I'm guessing that the video player is loading the entire video, or at least a massive chunk of it) before it plays. That's why Protocols like "HTTP Live Stream" solve this problem and lead to videos playing nearly instantly, as the protocol sends chunks of videos, and adjusts the bandwidth dynamically.
3. Your internet connection is relatively slow
While this is probably not the main cause, it might affect the outcome.
推荐阅读
- cassandra - Cassandra 调试日志分析
- reactjs - 为什么调用一个api时数据不更新,调用另一个api时更新好?
- vue.js - Vue - 根据父事件发出 axios 请求
- flutter - 完全编码 UI 并且仅在构建业务逻辑 [Flutter] 之后是否方便?
- ios - 快速替换第一次出现的字符串
- python - 设置 tk.NoDefaultRoot 时设置主 TopLevel
- python-3.x - 如何使用地图函数python对二维列表中的每个元素进行平方
- firebase - Firestore 存储文件命名
- apache-kafka - 5 节点代理集群的 Kafka 复制因子
- reactjs - 反应useState,useEffect中的setState不更新数组