【发布时间】:2019-01-07 11:08:10
【问题描述】:
我正在使用一个简单的 exoplayer 测试代码从 URL 播放视频,我注意到播放器连接后,它会缓冲大约 2-3 秒,直到它开始播放(我指的是大约 2-3 秒,因为我这样做了不知道它在内部是如何工作的,它可能是一定数量的字节)。考虑到连接大约需要 1-2 秒(然后开始缓冲,然后有效地开始视频),开始视频需要大约 4 秒,这似乎太多了。我测试了一个 3 秒的视频,640x480,大小为 1.23MB,使用速度测试应用程序在检测到的速度 ~24Mbits/s 的连接上)。
有没有办法加快视频的启动速度(例如,通过设置启动所需的初始缓冲大小)?
这是我的测试代码:
TrackSelector trackSelector = new DefaultTrackSelector();
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
PlayerView playerView = findViewById(R.id.player_view);
playerView.setPlayer(player);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "simpleAudioApp"));
dataSourceFactory = new CacheDataSourceFactory(getSimpleCacheInstance(),
dataSourceFactory);
Uri audioSourceUri = Uri.parse("http://...somevideo.mp4");
MediaSource audioSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(audioSourceUri);
LoopingMediaSource loopingSource = new LoopingMediaSource(audioSource, 1);
// Prepare the player with the source.
player.prepare(loopingSource);
player.setPlayWhenReady(true);
player.addListener(new Player.EventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == Player.STATE_ENDED) {
Toast.makeText(TestActivity2.this, "Video ended", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(TestActivity2.this, "video state chnged: " + playbackState, Toast.LENGTH_LONG).show();
}
}
@Override
public void onRepeatModeChanged(int repeatMode) {
Toast.makeText(TestActivity2.this, "repeat chnged: " + repeatMode, Toast.LENGTH_LONG).show();
}
});
有什么方法可以实现吗?
【问题讨论】:
-
在这里阅读 - stackoverflow.com/questions/27128904/… 或 stackoverflow.com/questions/50671723/… - 您需要优化视频,以便尽快使用它
标签: java android video exoplayer