Reputation: 904
In an Android App, I am trying to play videos from URL using Exoplayer. For .mp4
files it plays fine including seeking features. But when I try with .mkv
videos it plays but seekbar (Timebar) looks like progressbar (doesn't support seeking by user). Also seek buttons do not get activated, nothing happens on click.
Tested with 50+ videos. File size of them are between 20mb to 150mb.
Another confusing observation is everything works with another .mkv
video with 13 sec duration and size less than 1mb.
Seek feature is not working for large .mkv
files. Tested with following link [Link removed after getting solution]
Seek feature is working for any .mp4
files and small .mkv
files. Works for the following link-
[Link removed after getting solution]
Here is my code from android side-
Dependency-
implementation 'com.google.android.exoplayer:exoplayer:2.10.5'
VideoPlayerActivity.java
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, getString(R.string.app_name)));
Map<String, String> headers = new HashMap<>();
headers.put("accept", "application/json");
headers.put(..., ...);
dataSourceFactory.getDefaultRequestProperties().set(headers);
//Also tested with
//DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, getString(R.string.app_name)));
MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(mUri);
player.prepare(videoSource);
player.setPlayWhenReady(true);
player.addListener(this);
Also tried applying-
DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
extractorsFactory.setConstantBitrateSeekingEnabled(true);
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.setExtractorsFactory(extractorsFactory)
.createMediaSource(mUri);
Is there any option to enable seeking for large .mkv
video files? Any other libraries will also be appreciated.
Update
If I try to seek programmatically with player.seekTo(15000);
video starts from beginning again.
Upvotes: 0
Views: 1238
Reputation: 904
I found that Exoplayer works fine with videos codec H.264 and audio codec AAC (May not be limited to) (Source: medium.com).
I converted my videos using ffmpeg with the command below and now mkv files with long duration are working fine for me.
ffmpeg -i input.mkv -vcodec libx264 -acodec aac -crf 28 output.mkv
-crf 28
is used to reduce file size keeping the quality almost same.
In my case-
crf
138M file became 54M in size.crf
138M file became 107M in size.Upvotes: 1