You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding new subtitle to a video on the fly requires to remove media source(both track and earlier subtitle source) and add it again?
Reproduction steps
I added a subtitle to a video with filename (say Video1.mp4) by searching the folder for subtitle with same name(Video1.srt) . I added this subtitle while preparing media source first time by merging and adding them to a ConcatenatingMediaSource. Is it the right way to find subtitle in folder and then add it to mediasource? Or is there a better way to do so ?
private ConcatenatingMediaSource finalMediaSource = new ConcatenatingMediaSource();
MediaSource mergedSource = new MergingMediaSource(trackSource,
buildSubtitleSource(subTitle));
finalMediaSource.addMediaSource(mergedSource);
On clicking subtitle button, user can sideload subtitle from storage and add it. The selected subtitle gets added and I add the old subtitle also too to TrackSelectionDialog so user change it if he wants. My question is that is my approach of removing the media source and adding it again right way? Is there a better way to just merge the new subtitle source to the existing media source? And is it possible to get name of the subtitle like how VLC player gets it (like Track1) or anything?
private Map<Uri, List<String>> pathSubtitleMapping = new HashMap<>(); // (uri, list of subs)
public void onSubSelected(String path) {
final long position = player.getCurrentPosition();
List<MediaSource> subtitleSource = new ArrayList<>();
Uri uri = uris[currentIndex];
MediaSource trackSource = buildMediaSource(uri);
List<String> subPaths;
if (!pathSubtitleMapping.containsKey(uri)) {
subPaths = new ArrayList<>();
subPaths.add(path);
subtitleSource.add(buildSubtitleSource(path));
pathSubtitleMapping.put(uris[currentIndex], subPaths);
} else {
subPaths = pathSubtitleMapping.get(uri);
if (!subPaths.contains(path)) {
subPaths.add(path);
}
for (String path1 : subPaths) {
subtitleSource.add(buildSubtitleSource(path1));
}
}
MediaSource mediaSources[] = new MediaSource[subtitleSource.size() + 1];
mediaSources[0] = trackSource;
int index = 1;
for (MediaSource source : subtitleSource) {
mediaSources[index] = source;
index++;
}
finalMediaSource.removeMediaSource(currentIndex);
finalMediaSource.addMediaSource(currentIndex, new MergingMediaSource(mediaSources), new Runnable() {
@Override
public void run() {
player.seekTo(currentIndex, position);
}
});
Link to test content
Mailed
Version of ExoPlayer being used
dev-v2 branch or dev-v2-r2.7.0
Device(s) and version(s) of Android being used
Any device/OS
The text was updated successfully, but these errors were encountered:
Adding subtitles during playback is not something we support currently. Implementing this is tracked by #1649. Marking this as a duplicate of that issue.
Issue description
Adding new subtitle to a video on the fly requires to remove media source(both track and earlier subtitle source) and add it again?
Reproduction steps
I added a subtitle to a video with filename (say Video1.mp4) by searching the folder for subtitle with same name(Video1.srt) . I added this subtitle while preparing media source first time by merging and adding them to a
ConcatenatingMediaSource
. Is it the right way to find subtitle in folder and then add it to mediasource? Or is there a better way to do so ?On clicking subtitle button, user can sideload subtitle from storage and add it. The selected subtitle gets added and I add the old subtitle also too to TrackSelectionDialog so user change it if he wants. My question is that is my approach of removing the media source and adding it again right way? Is there a better way to just merge the new subtitle source to the existing media source? And is it possible to get name of the subtitle like how VLC player gets it (like Track1) or anything?
Link to test content
Mailed
Version of ExoPlayer being used
dev-v2 branch or dev-v2-r2.7.0
Device(s) and version(s) of Android being used
Any device/OS
The text was updated successfully, but these errors were encountered: