Exemplo n.º 1
0
    @Override
    public void run() {
      try {
        String line;
        while ((line = reader.readLine()) != null) {
          Matcher matcher = Pattern.compile(MediaInfo.INPUT_PATTERN).matcher(line);
          if (matcher.find()) {
            currentMediaInfo = new MediaInfo();
            mediaInfos.add(currentMediaInfo);
            continue;
          }

          matcher = Pattern.compile(MediaInfo.DURATION_PATTERN).matcher(line);
          if (matcher.find()) {
            currentMediaInfo.setDuration(matcher.group(1));
            currentMediaInfo.setBitrate(matcher.group(4));
            continue;
          }

          matcher = Pattern.compile(VideoStreamInfo.PATTERN).matcher(line);
          if (matcher.find()) {
            VideoStreamInfo videoStreamInfo = new VideoStreamInfo();
            videoStreamInfo.setId(matcher.group(1));
            videoStreamInfo.setLanguage(matcher.group(3));
            videoStreamInfo.setEncoder(matcher.group(4));
            videoStreamInfo.setResolution(matcher.group(6));
            videoStreamInfo.setDefaultStream(matcher.group(8) != null);
            currentMediaInfo.getVideoStreams().add(videoStreamInfo);
            continue;
          }

          matcher = Pattern.compile(AudioStreamInfo.PATTERN).matcher(line);
          if (matcher.find()) {
            AudioStreamInfo audioStreamInfo = new AudioStreamInfo();
            audioStreamInfo.setId(matcher.group(1));
            audioStreamInfo.setLanguage(matcher.group(3));
            audioStreamInfo.setEncoder(matcher.group(4));
            audioStreamInfo.setFrequency(matcher.group(6));
            audioStreamInfo.setChannels(matcher.group(7));
            audioStreamInfo.setDefaultStream(matcher.group(8) != null);

            currentMediaInfo.getAudioStreams().add(audioStreamInfo);
          }
        }
      } catch (Exception e) {
        /* ignore */
      } finally {
        try {
          reader.close();
        } catch (IOException e) {
          /* ignore */
        }
      }
    }