Package com.castlabs.android.player.filter

## Interface PlayerModelFilter

- All Known Implementing Classes:
    `AbstractPlayerModelFilter`

      public interface PlayerModelFilter

  Interface which allows to filter `Tracks`, before the `PlayerModel` is built. An instance of the Filter should be added to the PlayerController before `opening` it.
  Each method should remove the non-desired tracks from the provided `Collections`.
  Example implementation:

       playerController.addPlayerModelFilter(new PlayerModelFilter() {
          @Override
          public void onVideoTracks(@NonNull Collection videoTracks) {
            // Build qualities, we want to keep only the highest bitrate track
            // for each resolution.
            SparseIntArray qualitiesMap = new SparseIntArray();
            for (VideoTrack track : videoTracks) {
                for (VideoTrackQuality quality : track.getQualities()) {
                    final int bitrate = quality.getBitrate();
                    final int width = quality.getWidth();
                    if (bitrate < 0 || width < 0) {
                        continue;
                    }
                    qualitiesMap.put(width, Math.max(bitrate, qualitiesMap.get(width)));
                }
            }

            // Apply filter
            for (MutableVideoTrack track : videoTracks) {
                for (VideoTrackQuality quality : track.getQualities()) {
                    if (qualitiesMap.get(quality.getWidth()) != quality.getBitrate()) {
                        track.removeQuality(quality);
                    }
                }
            }
          }

          @Override
          public void onAudioTracks(@NonNull Collection audioTracks) {
            // Remove italian audio tracks
            for (Iterator iterator = audioTracks.iterator(); iterator.hasNext(); ) {
                AudioTrack audioTrack = iterator.next();
                if (audioTrack.getLanguage().toLowerCase().contains("it")) {
                    iterator.remove();
                  }
            }
          }

          @Override
          public void onSubtitleTracks(@NonNull Collection subtitleTracks) {
            // Remove French subtitle tracks
            for (Iterator iterator = subtitleTracks.iterator(); iterator.hasNext(); ) {
                SubtitleTrack subtitleTrack = iterator.next();
                if (subtitleTrack.getLanguage().toLowerCase().contains("fr")) {
                    iterator.remove();
                }
            }
          }
       });

       playerController.open(playbackBundle);

  Since:
    4.2.26

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `onAudioTracks​(Collection<AudioTrack> audioTracks)` | Apply custom filter logic on AudioTracks.
    `void` | `onSubtitleTracks​(Collection<SubtitleTrack> subtitleTracks)` | Apply custom filter logic on SubtitleTracks.
    `void` | `onVideoTracks​(Collection<MutableVideoTrack> videoTracks)` | Apply custom filter logic on VideoTracks.

- - ### Method Detail

    - #### onVideoTracks

          void onVideoTracks​(@NonNull
                             Collection<MutableVideoTrack> videoTracks)

      Apply custom filter logic on VideoTracks. If `qualities` are to be filtered, this can be achieved by calling `MutableVideoTrack.removeQuality(VideoTrackQuality)` on its parent `VideoTrack`.
      Parameters:
        `videoTracks` - tracks to filter

    - #### onAudioTracks

          void onAudioTracks​(@NonNull
                             Collection<AudioTrack> audioTracks)

      Apply custom filter logic on AudioTracks.
      Parameters:
        `audioTracks` - tracks to filter

    - #### onSubtitleTracks

          void onSubtitleTracks​(@NonNull
                                Collection<SubtitleTrack> subtitleTracks)

      Apply custom filter logic on SubtitleTracks.
      Parameters:
        `subtitleTracks` - tracks to filter