Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new subtitles on the fly #3941

Closed
nerd-sj opened this issue Mar 4, 2018 · 1 comment
Closed

Add new subtitles on the fly #3941

nerd-sj opened this issue Mar 4, 2018 · 1 comment

Comments

@nerd-sj
Copy link

nerd-sj commented Mar 4, 2018

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 ?

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

@ojw28 ojw28 added the duplicate label Mar 5, 2018
@ojw28
Copy link
Contributor

ojw28 commented Mar 5, 2018

Adding subtitles during playback is not something we support currently. Implementing this is tracked by #1649. Marking this as a duplicate of that issue.

@ojw28 ojw28 closed this as completed Mar 5, 2018
@google google locked and limited conversation to collaborators Aug 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants