コード例 #1
0
  public synchronized InputStream getStream(PlaylistItem playlistItem) {
    MetadataThread metadataThread = metadataFetchers.get(playlistItem);

    try {
      return metadataThread.getPlayingStream();
    } catch (NullPointerException e) {
      return null;
    }
  }
コード例 #2
0
  public synchronized void remove(PlaylistItem playlistItem) {
    MetadataThread metadataThread = metadataFetchers.get(playlistItem);

    if (metadataThread != null) {
      metadataThread.stopFetching();

      try {
        metadataThread.join();

        metadataFetchers.remove(playlistItem);
      } catch (InterruptedException e) {
        e.printStackTrace();
        System.out.println("Error joining thread for playlist item: " + playlistItem);
      }
    }
  }
コード例 #3
0
  public synchronized void add(PlaylistItem playlistItem) {
    MetadataThread metadataThread = metadataFetchers.get(playlistItem);

    // only add if it doesn't exist already
    if (metadataThread == null) {

      try {
        // get the headers from the playlistItem url
        Map<String, List<String>> headers = new HashMap<>();
        InputStream inputStream = IMPNetworkUtilities.getHeaders(playlistItem, headers);

        // work out type of stream from headers
        StreamType streamType =
            IMPMetadataUtilities.getStreamType(playlistItem.getInternalURL(), headers);

        if (streamType == StreamType.Shoutcast) {
          MetadataThread shoutcastMetadataThread =
              new ShoutcastMetadataThread(
                  playlistItem,
                  inputStream,
                  Integer.parseInt(headers.get("icy-metaint").get(0)),
                  this);
          shoutcastMetadataThread.setName(playlistItem.getURL().toString());
          metadataFetchers.put(playlistItem, shoutcastMetadataThread);
          shoutcastMetadataThread.start();
        } else if (streamType == StreamType.Live365) {
          MetadataThread live365MetadataThread =
              new Live365MetadataThread(playlistItem, inputStream, this);
          live365MetadataThread.setName(playlistItem.getURL().toString());
          metadataFetchers.put(playlistItem, live365MetadataThread);
          live365MetadataThread.start();
        }

      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }