Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

ALL-3995/Add subtitles functionality #47

Merged

Conversation

joetimmins
Copy link
Contributor

Problem

We weren't showing subtitles in our NoPlayer demo app.

Solution

We added the concept of a PlayerSubtitlesView as an interface, so we had something the player could call back to in order to show subtitles.

We added methods to our Player interface to get the subtitle tracks from a video, show a specific subtitle track, or show just the first available track. We also added a method to hide subtitles.

We have also provided dynamic indexing for all renderer tracks. Before, we were hardcoding the track at position 0 to always be audio.

Test(s) added

We tested the ExoPlayerImpl class around the new subtitles methods we added.

Screenshots

After
subtitles-on

Paired with

@zegnus

@juankysoriano juankysoriano self-requested a review June 16, 2017 14:39
@juankysoriano juankysoriano self-assigned this Jun 16, 2017
@Dorvaryn Dorvaryn self-requested a review June 16, 2017 14:40
@Dorvaryn Dorvaryn self-assigned this Jun 16, 2017

import java.util.List;

public interface PlayerSubtitlesView {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about renaming to SubtiteableView and making PlayerView extend SubtiteableView?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise I think this is still ok, but maybe with a renaming, PlayerSubtitlesView sounds weird to me (maybe just me)

@@ -33,8 +33,18 @@

void selectAudioTrack(PlayerAudioTrack audioTrack);

boolean hasAvailableSubtitles();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an equivalent method for audioTrack?

Copy link
Contributor

@zegnus zegnus Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the current impl assumes that there is always an audio track but that might not be the case for the subtitles

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't using getSubtitleTracks and checking for empty enough ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, will remove


void selectSubtitleTrack(PlayerSubtitleTrack subtitleTrack, PlayerSubtitlesView playerSubtitlesView);

void selectFirstAvailableSubtitleTrack(PlayerSubtitlesView playerSubtitlesView);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an equivalent method for audioTrack? If we don't how do we select the first available one for audio? We should push for symmetry

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. We should push for symmetry, I'd rather avoid having lots of helper methods that is going to make the Player interface bloat.


void selectFirstAvailableSubtitleTrack(PlayerSubtitlesView playerSubtitlesView);

void clearSubtitleTrack(PlayerSubtitlesView playerSubtitlesView);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be an use case for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will rename to hide...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invoked when the user wants to turn subtitles off


import java.util.List;

public interface PlayerSubtitlesView {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I don't like about this interface that it is supposed to be used on both implementation of Player but it is coupled with exoplayer. Maybe we could find a way to pass something else than com.google.android.exoplayer2.text.Cue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. We should avoid using ExoPlayer or MediaPlayer specific code in the no-player part of this library.

public List<PlayerAudioTrack> getAudioTracks() {
return mediaPlayer.getAudioTracks();
}

@Override
public List<PlayerSubtitleTrack> getSubtitleTracks() {
SubtitlesError subtitlesError = new SubtitlesError("Subtitles not implemented for Android Media Player", new IllegalStateException());
listenersHolder.getErrorListeners().onError(this, subtitlesError);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

TrackGroupArray trackGroups,
MappingTrackSelector.SelectionOverride selectionOverride) {
Optional<Integer> audioRendererIndex = rendererTrackIndexExtractor.extract(trackType, mappedTrackInfoLength(), rendererTypeRequester);
if (audioRendererIndex.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being absent is a case that should not happen right? I think w should warn the caller it didn't work so that we can bubble up until we can send an error though the ErrorListener.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We considered to return a boolean in the method indicating if it was ok or not and bubble up to the client, what about that? This should not be possible as this method requires a trackGroups that is retrieved by a get by type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to do yep, if this happens we did something wrong and being warned rather than swallowing would help to catch it faster.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, also added lots of tests 6794007

public void selectFirstTextTrack(RendererTypeRequester rendererTypeRequester) {
List<PlayerSubtitleTrack> subtitleTracks = getSubtitleTracks(rendererTypeRequester);
if (subtitleTracks.isEmpty()) {
NoPlayerLog.e("No subtitles tracks available");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we bubble back up to warn through the ErrorListener ? Seems like a feedback the user of the lib should have

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not used anymore, will remove :)

import com.novoda.noplayer.PlayerView;
import com.novoda.noplayer.SurfaceHolderRequester;
import com.novoda.noplayer.Timeout;
import com.novoda.noplayer.VideoDuration;
import com.novoda.noplayer.VideoPosition;
import com.novoda.noplayer.exoplayer.playererror.SubtitlesError;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This cannot be here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh 😆

@zegnus zegnus changed the base branch from exo-player-2 to ALL-3995/feature-branch-select-subtitles June 19, 2017 14:41
@zegnus
Copy link
Contributor

zegnus commented Jun 19, 2017

test this please

@juankysoriano juankysoriano merged commit 65a817f into ALL-3995/feature-branch-select-subtitles Jun 19, 2017
@juankysoriano juankysoriano deleted the ALL-3995/select-subtitles branch June 19, 2017 14:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants