Control closed-caption visibility

You can control the visibility of closed captions. When visibility is on, the currently selected track is displayed. If you change which track is current, the visibility setting remains the same.


If closed caption text is displayed when the player enters the seek mode, the text no longer displays after the seek completes. Instead, after a few seconds, TVSDK displays the next closed caption text in the video after the ending seek position.


The visibility values for closed captions are defined in ClosedCaptionsVisibility.

public static const HIDDEN:String = hidden;
public static const VISIBLE:String = visible;
  1. Wait for the MediaPlayer to have at least the PREPARED status (see Wait for a valid state).

  2. To get the current visibility setting for closed captions, use the getter method in MediaPlayer, which returns a visibility value.

    public function get ccVisibility():String
  3. To change the visibility for closed captions, use the setter method, passing a visibility value from ClosedCaptionsVisibility.

    For example:

    public function set ccVisibility(value:String):void
  4. Define a drop-down list.

    <s:DropDownList id="ccTracksList" width="85"
  5. Define a bindable array of closed caption tracks.

    [Bindable] private var _ccTracks:ArrayCollection =
      new ArrayCollection(); // active tracks
  6. Set up listeners.

    player.addEventListener(MediaPlayerItemEvent.ITEM_CREATED, onItemCreated);
    player.addEventListener(MediaPlayerItemEvent.CAPTIONS_UPDATED, onCaptionUpdated);

    To remove the listeners from your destruction code:

    player.removeEventListener(MediaPlayerItemEvent.ITEM_CREATED, onItemCreated);
    player.removeEventListener(MediaPlayerItemEvent.CAPTIONS_UPDATED, onCaptionUpdated);
  7. Create and update the list when a user makes a choice from the list.

    private function onCCTrackChange(event:IndexChangeEvent):void {
        var ccTrackIndex:int = event.newIndex;
        var ccTracks:Vector.<ClosedCaptionsTrack> =
        if (ccTrackIndex == 0) {
            _player.ccVisibility = MediaPlayer.INVISIBLE;
        else if (ccTrackIndex <= _ccTracks.length) {
            var index:Number = findFromActiveIndex(ccTracks, ccTrackIndex - 1);
            _player.ccVisibility = MediaPlayer.VISIBLE;
    private function findFromActiveIndex(ccTracks:Vector.<ClosedCaptionsTrack>,
      ccTrackIndex:int):Number {
        var count:Number = 0;
        for each (var ccTrack:ClosedCaptionsTrack in ccTracks) {
            if (count < ccTrackIndex)
                count = count + 1;
                return count;
        return -1;
    private function onItemCreated(event:MediaPlayerItemEvent):void {
        ... (you are likely to need more code here for other reasons)
    private function onCaptionUpdated(event:MediaPlayerItemEvent):void {
        ... (you are likely to need more code here for other reasons)
                      (_player.ccVisibility == MediaPlayer.VISIBLE) ?
                       _player.currentItem.selectedClosedCaptionsTrack : null);
    private function updateCCTracks(tracks:Vector.<ClosedCaptionsTrack>,
      selectedTrack:ClosedCaptionsTrack = null):void {
                "label": "CC off",
                "data": "cc-off"
        var selectedIndex:int = 0;
        for each (var ccTrack:ClosedCaptionsTrack in tracks) {
            if (selectedTrack && == &&
            ccTrack.language == selectedTrack.language &&
            ccTrack.serviceType == selectedTrack.serviceType) {
                selectedIndex = _ccTracks.length - 1;
        var hasCC:Boolean = _ccTracks.length > 0;
        ccTracksList.enabled = hasCC;
        ccTracksList.mouseEnabled = hasCC;
        ccTracksList.selectedIndex = selectedIndex;

On this page