Methods Summary |
---|
public SubtitleTrack | addTrack(MediaFormat format)Adds a new, external subtitle track to the manager.
synchronized(mRenderers) {
for (Renderer renderer: mRenderers) {
if (renderer.supports(format)) {
SubtitleTrack track = renderer.createTrack(format);
if (track != null) {
synchronized(mTracks) {
if (mTracks.size() == 0) {
mCaptioningManager.addCaptioningChangeListener(
mCaptioningChangeListener);
}
mTracks.add(track);
}
return track;
}
}
}
}
return null;
|
private void | checkAnchorLooper()
assert mHandler != null : "Should have a looper already";
assert Looper.myLooper() == mHandler.getLooper() : "Must be called from the anchor's looper";
|
private void | doHide()
mVisibilityIsExplicit = true;
if (mSelectedTrack != null) {
mSelectedTrack.hide();
}
mShowing = false;
|
private void | doSelectDefaultTrack()
if (mTrackIsExplicit) {
// If track selection is explicit, but visibility
// is not, it falls back to the captioning setting
if (!mVisibilityIsExplicit) {
if (mCaptioningManager.isEnabled() ||
(mSelectedTrack != null &&
mSelectedTrack.getFormat().getInteger(
MediaFormat.KEY_IS_FORCED_SUBTITLE, 0) != 0)) {
show();
} else if (mSelectedTrack != null && !mSelectedTrack.isTimedText()) {
hide();
}
mVisibilityIsExplicit = false;
}
return;
}
// We can have a default (forced) track even if captioning
// is not enabled. This is handled by getDefaultTrack().
// Show this track unless subtitles were explicitly hidden.
SubtitleTrack track = getDefaultTrack();
if (track != null) {
selectTrack(track);
mTrackIsExplicit = false;
if (!mVisibilityIsExplicit) {
show();
mVisibilityIsExplicit = false;
}
}
|
private void | doSelectTrack(SubtitleTrack track)
mTrackIsExplicit = true;
if (mSelectedTrack == track) {
return;
}
if (mSelectedTrack != null) {
mSelectedTrack.hide();
mSelectedTrack.setTimeProvider(null);
}
mSelectedTrack = track;
if (mAnchor != null) {
mAnchor.setSubtitleWidget(getRenderingWidget());
}
if (mSelectedTrack != null) {
mSelectedTrack.setTimeProvider(mTimeProvider);
mSelectedTrack.show();
}
if (mListener != null) {
mListener.onSubtitleTrackSelected(track);
}
|
private void | doShow()
mShowing = true;
mVisibilityIsExplicit = true;
if (mSelectedTrack != null) {
mSelectedTrack.show();
}
|
protected void | finalize()
mCaptioningManager.removeCaptioningChangeListener(
mCaptioningChangeListener);
super.finalize();
|
public SubtitleTrack | getDefaultTrack()
SubtitleTrack bestTrack = null;
int bestScore = -1;
Locale selectedLocale = mCaptioningManager.getLocale();
Locale locale = selectedLocale;
if (locale == null) {
locale = Locale.getDefault();
}
boolean selectForced = !mCaptioningManager.isEnabled();
synchronized(mTracks) {
for (SubtitleTrack track: mTracks) {
MediaFormat format = track.getFormat();
String language = format.getString(MediaFormat.KEY_LANGUAGE);
boolean forced =
format.getInteger(MediaFormat.KEY_IS_FORCED_SUBTITLE, 0) != 0;
boolean autoselect =
format.getInteger(MediaFormat.KEY_IS_AUTOSELECT, 1) != 0;
boolean is_default =
format.getInteger(MediaFormat.KEY_IS_DEFAULT, 0) != 0;
boolean languageMatches =
(locale == null ||
locale.getLanguage().equals("") ||
locale.getISO3Language().equals(language) ||
locale.getLanguage().equals(language));
// is_default is meaningless unless caption language is 'default'
int score = (forced ? 0 : 8) +
(((selectedLocale == null) && is_default) ? 4 : 0) +
(autoselect ? 0 : 2) + (languageMatches ? 1 : 0);
if (selectForced && !forced) {
continue;
}
// we treat null locale/language as matching any language
if ((selectedLocale == null && is_default) ||
(languageMatches &&
(autoselect || forced || selectedLocale != null))) {
if (score > bestScore) {
bestScore = score;
bestTrack = track;
}
}
}
}
return bestTrack;
|
private android.media.SubtitleTrack.RenderingWidget | getRenderingWidget()
if (mSelectedTrack == null) {
return null;
}
return mSelectedTrack.getRenderingWidget();
|
public SubtitleTrack | getSelectedTrack()
return mSelectedTrack;
|
public SubtitleTrack[] | getTracks()
synchronized(mTracks) {
SubtitleTrack[] tracks = new SubtitleTrack[mTracks.size()];
mTracks.toArray(tracks);
return tracks;
}
|
public boolean | hasRendererFor(MediaFormat format)
synchronized(mRenderers) {
// TODO how to get available renderers in the system
for (Renderer renderer: mRenderers) {
if (renderer.supports(format)) {
return true;
}
}
return false;
}
|
public void | hide()Hide the selected (or default) subtitle track.
Should be called from the anchor's (UI) thread. {@see #Anchor.getSubtitleLooper}
processOnAnchor(mHandler.obtainMessage(WHAT_HIDE));
|
private void | processOnAnchor(android.os.Message m)
assert mHandler != null : "Should have a looper already";
if (Looper.myLooper() == mHandler.getLooper()) {
mHandler.dispatchMessage(m);
} else {
mHandler.sendMessage(m);
}
|
public void | registerRenderer(android.media.SubtitleController$Renderer renderer)Add support for a subtitle format in {@link MediaPlayer}.
synchronized(mRenderers) {
// TODO how to get available renderers in the system
if (!mRenderers.contains(renderer)) {
// TODO should added renderers override existing ones (to allow replacing?)
mRenderers.add(renderer);
}
}
|
public void | reset()
checkAnchorLooper();
hide();
selectTrack(null);
mTracks.clear();
mTrackIsExplicit = false;
mVisibilityIsExplicit = false;
mCaptioningManager.removeCaptioningChangeListener(
mCaptioningChangeListener);
|
public void | selectDefaultTrack()
processOnAnchor(mHandler.obtainMessage(WHAT_SELECT_DEFAULT_TRACK));
|
public boolean | selectTrack(SubtitleTrack track)Selects a subtitle track. As a result, this track will receive
in-band data from the {@link MediaPlayer}. However, this does
not change the subtitle visibility.
Should be called from the anchor's (UI) thread. {@see #Anchor.getSubtitleLooper}
if (track != null && !mTracks.contains(track)) {
return false;
}
processOnAnchor(mHandler.obtainMessage(WHAT_SELECT_TRACK, track));
return true;
|
public void | setAnchor(android.media.SubtitleController$Anchor anchor)
if (mAnchor == anchor) {
return;
}
if (mAnchor != null) {
checkAnchorLooper();
mAnchor.setSubtitleWidget(null);
}
mAnchor = anchor;
mHandler = null;
if (mAnchor != null) {
mHandler = new Handler(mAnchor.getSubtitleLooper(), mCallback);
checkAnchorLooper();
mAnchor.setSubtitleWidget(getRenderingWidget());
}
|
public void | show()Show the selected (or default) subtitle track.
Should be called from the anchor's (UI) thread. {@see #Anchor.getSubtitleLooper}
processOnAnchor(mHandler.obtainMessage(WHAT_SHOW));
|