-
Notifications
You must be signed in to change notification settings - Fork 28
ALL-3995/Add subtitles functionality #47
ALL-3995/Add subtitles functionality #47
Conversation
… in the demo application
|
||
import java.util.List; | ||
|
||
public interface PlayerSubtitlesView { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will rename to hide...
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh 😆
test this please |
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
Paired with
@zegnus