예제 #1
0
 public static String createMetaData(String title, PlaylistItem.Type type) {
   Item item = null;
   switch (type) {
     case AUDIO:
       item = new AudioItem("", "", title, "", new Res[0]);
       break;
     case VIDEO:
       item = new VideoItem("", "", title, "", new Res[0]);
       break;
     case IMAGE:
       item = new ImageItem("", "", title, "", new Res[0]);
       break;
     default:
       break;
   }
   if (item != null) {
     DIDLParser ps = new DIDLParser();
     DIDLContent ct = new DIDLContent();
     ct.addItem(item);
     try {
       return ps.generate(ct);
     } catch (Exception e) {
       return "";
     }
   } else {
     return "";
   }
 }
  public void addDidlNodes(DIDLContent didl, JSONArray browse) throws JSONException {
    for (int i = 0; i < browse.length(); i++) {
      JSONObject obj = browse.getJSONObject(i);
      String url = obj.getString("browse");
      String label = obj.getString("name");
      String thumbnail = obj.optString("image");
      String type = obj.optString("type");

      Integer subCount = Integer.parseInt(obj.optString("count", "10"));

      // Hack so we can easily get container label in request for metadata.
      try {
        url += "&label=" + URLEncoder.encode(label, "UTF-8");
      } catch (UnsupportedEncodingException e) {
      }

      // TODO: Use Album/Artist containers where appropriate. Check "type" field.
      // Container folder = new StorageFolder(url,"0",label,"Me", subCount, storageUsed);
      DIDLObject.Class containerClass;
      if (type == null) type = "";

      type = type.toLowerCase();
      if (type.equals("album")) {
        containerClass = MusicAlbum.CLASS;
      } else if (type.equals("artist")) {
        containerClass = ARTIST_CLASS;
      } else if (type.equals("genre")) {
        containerClass = MusicGenre.CLASS;
      } else {
        containerClass = CONTAINER_CLASS;
      }

      Container folder = new Container(url, "0", label, "System", containerClass, subCount);
      String playlist = obj.optString("playlink");
      if (playlist != null && playlist.length() > 0) {
        MimeType mimeType = new MimeType("audio", "m3u");
        Res res = new Res();
        res.setProtocolInfo(new ProtocolInfo(mimeType));
        res.setValue(playlist);
        folder.addResource(res);

        if (thumbnail != null && thumbnail.length() > 0) {
          try {
            URI uri = new URI(thumbnail);
            ALBUM_ART_URI albumArt = new ALBUM_ART_URI(uri);
            // TODO: DLNA requires xml attribute:
            // dlna:profileID="JPEG_TN" for jpeg thumbnails.
            folder.addProperty(albumArt);
          } catch (URISyntaxException e) {
            Log.w(TAG, "Found album art but bad URI", e);
          }
        }
      }
      didl.addContainer(folder);
    }
  }
 public void addDidlTracks(DIDLContent didl, JSONArray browse) {
   for (int i = 0; i < browse.length(); i++) {
     try {
       JSONObject track = browse.getJSONObject(i);
       MusicTrack musicTrack = JinzoraApi.jsonToMusicTrack(track);
       didl.addItem(musicTrack);
     } catch (Exception e) {
       Log.w(TAG, "Bad json entry", e);
     }
   }
 }