示例#1
0
  @Override
  protected void processHeaders(URLConnection cn) {
    super.processHeaders(cn);

    for (java.util.Map.Entry<String, java.util.List<String>> me : cn.getHeaderFields().entrySet()) {
      if ("content-type".equalsIgnoreCase(me.getKey())) {
        for (String s : me.getValue()) {
          String ct = s;

          if (!s.startsWith("audio/")) {
            Logging.log(APP_TAG, "Content type not audio: " + s);
            continue;
          }

          s = s.substring("audio/".length());
          if (s.startsWith("x-")) s = s.substring("x-".length());

          // MP3: audio/mpeg, audio/x-mpeg, audio/mp3, audio/x-mp3,
          //      audio/mpeg3, audio/x-mpeg3, audio/mpg, audio/x-mpg, audio/x-mpegaudio
          boolean isMp3 = s.startsWith("mp3") || s.startsWith("mpeg") || s.startsWith("mpg");

          Logging.log(
              APP_TAG, "Setting " + (isMp3 ? "MP3" : "AAC") + " decoder for content type " + ct);
          setDecoder(isMp3 ? mp3Decoder : aacDecoder);

          return;
        }

        Logging.log(APP_TAG, "Content type not recognized");
      }
    }

    Logging.log(APP_TAG, "Could not recognize the type of the stream.");
    throw new RuntimeException("Could not recognize the type of the stream.");
  }
示例#2
0
  @Override
  protected Decoder createDecoder() {
    aacDecoder = super.createDecoder();

    String name = "OpenCORE-MP3";

    mp3Decoder = Decoder.createByName(name);

    if (mp3Decoder == null) {
      Logging.log(APP_TAG, "Cannot find decoder by name '" + name + "'");
      throw new RuntimeException("MP3 Decoder not found");
    }

    return aacDecoder;
  }