static void modeAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { TextTrack* imp = V8TextTrack::toNative(info.Holder()); V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, v, value); imp->setMode(v); return; }
void MediaControls::disableShowingTextTracks() { TextTrackList* trackList = mediaElement().textTracks(); for (unsigned i = 0; i < trackList->length(); ++i) { TextTrack* track = trackList->anonymousIndexedGetter(i); if (track->mode() == TextTrack::showingKeyword()) track->setMode(TextTrack::disabledKeyword()); } }
void MediaControls::showTextTrackAtIndex(unsigned indexToEnable) { TextTrackList* trackList = mediaElement().textTracks(); if (indexToEnable >= trackList->length()) return; TextTrack* track = trackList->anonymousIndexedGetter(indexToEnable); if (track && track->canBeRendered()) track->setMode(TextTrack::showingKeyword()); }
void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGroup& group) { ASSERT(group.tracks.size()); // First, find the track in the group that should be enabled (if any). HeapVector<Member<TextTrack>> currentlyEnabledTracks; TextTrack* trackToEnable = nullptr; TextTrack* defaultTrack = nullptr; TextTrack* preferredTrack = nullptr; TextTrack* fallbackTrack = nullptr; int highestTrackScore = 0; for (size_t i = 0; i < group.tracks.size(); ++i) { TextTrack* textTrack = group.tracks[i]; if (m_configuration.disableCurrentlyEnabledTracks && textTrack->mode() == TextTrack::showingKeyword()) currentlyEnabledTracks.append(textTrack); int trackScore = textTrackSelectionScore(*textTrack); if (textTrack->kind() == preferredTrackKind()) trackScore += 1; if (trackScore) { // * If the text track kind is subtitles or captions and the user has indicated an interest in having a // track with this text track kind, text track language, and text track label enabled, and there is no // other text track in the media element's list of text tracks with a text track kind of either subtitles // or captions whose text track mode is showing // Let the text track mode be showing. if (trackScore > highestTrackScore) { preferredTrack = textTrack; highestTrackScore = trackScore; } if (!defaultTrack && textTrack->isDefault()) defaultTrack = textTrack; if (!fallbackTrack) fallbackTrack = textTrack; } else if (!group.visibleTrack && !defaultTrack && textTrack->isDefault()) { // * If the track element has a default attribute specified, and there is no other text track in the media // element's list of text tracks whose text track mode is showing or showing by default // Let the text track mode be showing by default. defaultTrack = textTrack; } } if (m_configuration.textTrackKindUserPreference != TextTrackKindUserPreference::Default) trackToEnable = preferredTrack; if (!trackToEnable && defaultTrack) trackToEnable = defaultTrack; if (!trackToEnable && m_configuration.forceEnableSubtitleOrCaptionTrack && group.kind == TrackGroup::CaptionsAndSubtitles) { if (fallbackTrack) trackToEnable = fallbackTrack; else trackToEnable = group.tracks[0]; } if (currentlyEnabledTracks.size()) { for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) { TextTrack* textTrack = currentlyEnabledTracks[i]; if (textTrack != trackToEnable) textTrack->setMode(TextTrack::disabledKeyword()); } } if (trackToEnable) trackToEnable->setMode(TextTrack::showingKeyword()); }