title: How to implement a custom SubtitleDecoderFactory which wraps SubtitleDecoderFactory.DEFAULT, which is a constant instance
body: <p>I am learning Exoplayer, and found a post at <a href="https://github.com/google/ExoPlayer/issues/4657" rel="nofollow noreferrer">https://github.com/google/ExoPlayer/issues/4657</a> (at the end of the post by erdemguven commented on 24 Aug 2018) regarding creating a wrapper SubtitleDecoderFactory which wraps SubtitleDecoderFactory.DEFAULT (at <a href="https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java" rel="nofollow noreferrer">https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java</a>). </p>
  
  <p>In another post at stackoverflow, I asked a question regarding SubtitleDecoderFactory.DEFAULT, from which I learnt that SubtitleDecoderFactory.DEFAULT is a constant instance. (at <a href="https://stackoverflow.com/questions/59494282/interface-implements-overriding-its-own-methods-to-create-an-object-of-itself-as">Interface implements overriding its own methods to create an object of itself as DEFAULT</a>)</p>
  
  <p>So here my questions are:</p>
  
  <ol>
  <li><p>Is it neccessary to wrap a constant instance, since the constant instance can be seen and referenced anywhere in the program?</p></li>
  <li><p>If there is a need to wrap this constant instance SubtitleDecoderFactory.DEFAULT, how would the codes be?</p></li>
  </ol>
  
  <p>This is the base interface SubtitleDecoderFactory (at <a href="https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java" rel="nofollow noreferrer">https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java</a>):</p>
  
  <pre><code>public interface SubtitleDecoderFactory {
  
  
    boolean supportsFormat(Format format);
  
  
    SubtitleDecoder createDecoder(Format format);
  
  
    SubtitleDecoderFactory DEFAULT =
        new SubtitleDecoderFactory() {
  
          @Override
          public boolean supportsFormat(Format format) {
            @Nullable String mimeType = format.sampleMimeType;
            return MimeTypes.TEXT_VTT.equals(mimeType)
                || MimeTypes.TEXT_SSA.equals(mimeType)
                || MimeTypes.APPLICATION_TTML.equals(mimeType)
                || MimeTypes.APPLICATION_MP4VTT.equals(mimeType)
                || MimeTypes.APPLICATION_SUBRIP.equals(mimeType)
                || MimeTypes.APPLICATION_TX3G.equals(mimeType)
                || MimeTypes.APPLICATION_CEA608.equals(mimeType)
                || MimeTypes.APPLICATION_MP4CEA608.equals(mimeType)
                || MimeTypes.APPLICATION_CEA708.equals(mimeType)
                || MimeTypes.APPLICATION_DVBSUBS.equals(mimeType)
                || MimeTypes.APPLICATION_PGS.equals(mimeType);
          }
  
          @Override
          public SubtitleDecoder createDecoder(Format format) {
            @Nullable String mimeType = format.sampleMimeType;
            if (mimeType != null) {
              switch (mimeType) {
                case MimeTypes.TEXT_VTT:
                  return new WebvttDecoder();
                case MimeTypes.TEXT_SSA:
                  return new SsaDecoder(format.initializationData);
                case MimeTypes.APPLICATION_MP4VTT:
                  return new Mp4WebvttDecoder();
                case MimeTypes.APPLICATION_TTML:
                  return new TtmlDecoder();
                case MimeTypes.APPLICATION_SUBRIP:
                  return new SubripDecoder();
                case MimeTypes.APPLICATION_TX3G:
                  return new Tx3gDecoder(format.initializationData);
                case MimeTypes.APPLICATION_CEA608:
                case MimeTypes.APPLICATION_MP4CEA608:
                  return new Cea608Decoder(mimeType, format.accessibilityChannel);
                case MimeTypes.APPLICATION_CEA708:
                  return new Cea708Decoder(format.accessibilityChannel, format.initializationData);
                case MimeTypes.APPLICATION_DVBSUBS:
                  return new DvbDecoder(format.initializationData);
                case MimeTypes.APPLICATION_PGS:
                  return new PgsDecoder();
                default:
                  break;
              }
            }
            throw new IllegalArgumentException(
                "Attempted to create decoder for unsupported MIME type: " + mimeType);
          }
        };
  }
  </code></pre>
  
  <p>My custom SubtitleDecoderFactory would look like:</p>
  
  <pre><code>public class mSubtitleDecoderFactory implements SubtitleDecoderFactory{
  
      @Override
      public boolean supportsFormat(Format format) {
          @Nullable String mimeType = format.sampleMimeType;
          return MimeTypes.TEXT_VTT.equals(mimeType)
                  || MimeTypes.TEXT_SSA.equals(mimeType)
                  || MimeTypes.APPLICATION_TTML.equals(mimeType)
                  || MimeTypes.APPLICATION_MP4VTT.equals(mimeType)
                  || MimeTypes.APPLICATION_SUBRIP.equals(mimeType)
                  || MimeTypes.APPLICATION_TX3G.equals(mimeType)
                  || MimeTypes.APPLICATION_CEA608.equals(mimeType)
                  || MimeTypes.APPLICATION_MP4CEA608.equals(mimeType)
                  || MimeTypes.APPLICATION_CEA708.equals(mimeType)
                  || MimeTypes.APPLICATION_DVBSUBS.equals(mimeType)
                  || MimeTypes.APPLICATION_PGS.equals(mimeType);
      }
  
      @Override
      public SubtitleDecoder createDecoder(Format format){
  
          @Nullable String mimeType = format.sampleMimeType;
          if (mimeType != null) {
              switch (mimeType) {
                  case MimeTypes.TEXT_VTT:
                      return new WebvttDecoder();
                  case MimeTypes.TEXT_SSA:
                      return new SsaDecoder(format.initializationData);
                  case MimeTypes.APPLICATION_MP4VTT:
                      return new Mp4WebvttDecoder();
                  case MimeTypes.APPLICATION_TTML:
                      return new TtmlDecoder();
                  case MimeTypes.APPLICATION_SUBRIP:
                      return new SubripDecoder();
                  case MimeTypes.APPLICATION_TX3G:
                      return new Tx3gDecoder(format.initializationData);
                  case MimeTypes.APPLICATION_CEA608:
                  case MimeTypes.APPLICATION_MP4CEA608:
                      return new Cea608Decoder(mimeType, format.accessibilityChannel);
                  case MimeTypes.APPLICATION_CEA708:
                      return new Cea708Decoder(format.accessibilityChannel, format.initializationData);
                  case MimeTypes.APPLICATION_DVBSUBS:
                      return new DvbDecoder(format.initializationData);
                  case MimeTypes.APPLICATION_PGS:
                      return new PgsDecoder();
                  default:
                      break;
              }
          }
          throw new IllegalArgumentException(
                  "Attempted to create decoder for unsupported MIME type: " + mimeType);
      };
  
  
  };
  </code></pre>
  
  <p>Basically it is overriding two abstract methods  <strong>"boolean supportsFormat(Format format)" and
   "SubtitleDecoder createDecoder(Format format)"</strong> declared in the base interface SubtitleDecoderFactory</p>
  
  <p>But where to put SubtitleDecoderFactory.DEFAULT as a parameter in oder to get wrapped?</p>
  
  <p>Thanks for your help in advance.</p>