Support download bundles
- Dominant language
- Java
- Stars
- 21.9k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
### [REQUIRED] Searched documentation and issues
Searched for info:
- in this repo
- in ExoPlayer sources and comments
- https://medium.com/google-exoplayer/
### [REQUIRED] Question
This is a hacky question, but is there a way to add SRT file as subtitles track in ManifestParser? (without using MergeSource)
I have HLS content + subtitles for it stored as a separate SRT file on the server. I would like to download HLS content with subtitles using download service as desribed here:
https://medium.com/google-exoplayer/downloading-streams-6d259eec7f95
General download works fine, but I cannot tell DownloadService to download SRT file because it is not a track (can't create StreamKey for it) until I merge it in using MergedMediaSource.
As a workaround I created a custom ManifestParser and custom HlsDownloadAction and HlsDownloader classes using custom ManifestParser. (This part works - I can download HLS successfully).
Then in manifest parser I try to create subtitles track artificially with:
```
private HlsMasterPlaylist parseMasterPlaylist(LineIterator iterator, String baseUri) throws IOException {
...
// adding my custom track here
subtitles.add(new HlsMasterPlaylist.HlsUrl(textTrack.getUrl(), buildTextFormat(textTrack.getLocale())));
return new HlsMasterPlaylist(baseUri, tags, variants, audios, subtitles, muxedAudioFormat,
muxedCaptionFormats, false, Collections.EMPTY_MAP);
}
```
This creates the track, but it does not work, because it expects url of the manifest and I provide url for SRT file. I have tried to intercept the request for this url and provide a "hand made" HlsPlaylist:
```
@Override
public HlsPlaylist parse(Uri uri, InputStream inputStream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
Queue extraLines = new ArrayDeque<>();
String line;
try {
// catch request for SRT file and provide artificial response
if (uri.toString().toLowerCase().endsWith(".srt")){
return mimicSubtitlesPlaylist(uri);
}
...
}
...
private HlsMediaPlaylist mimicSubtitlesPlaylist(Uri uri){
List segments = new ArrayList<>();
segments.add(new Segment(
uri.toString(),
0,
-1
));
return new HlsMediaPlaylist(
0,
uri.toString(),
new ArrayList(),
0,
0,
false,
0,
0,
1,
Long.MAX_VALUE,
false,
false,
false,
null,
segments);
}
```
But this also fails (it hangs forever on buffering when I try to enable this track with selection override).
I'm quite sure that there is a way to add SRT file as a track, but got somewhat lost in codes.
Could you give me some clues how to get there?
Contributor guide
Assessment
This issue has not been assessed yet.