Package org.teleal.cling.support.model.container

Examples of org.teleal.cling.support.model.container.MusicAlbum


//          upnpMusicArtist.setGenres(artistGenres.toArray(new String[0]));
//        }

      } else if (browsedItem.getType().equals("Release") ) {
        ResultItem<ReleaseEntity> releaseItem = (ResultItem<ReleaseEntity>) browsedItem;
        MusicAlbum upnpAlbum = new MusicAlbum();
        upnpContainer = upnpAlbum;
        List<PersonWithRole> contributors =  new ArrayList<PersonWithRole>();
       
//        try {

        Collection<ResultItem<ArtistEntity>> artists =
          artistBrowseService.findChildren(Arrays.asList(releaseItem.getId()), null, 0, null, false).getItems();
       
        for(ResultItem<ArtistEntity> artist : artists) {
          // TODO: replace hard coded "performer" by SMD role
           contributors.add(new PersonWithRole(artist.getItem().getName(), "Performer"));
        }
       
        upnpAlbum.setArtists(contributors.toArray(new PersonWithRole[0] ));
// TODO: check what happens if there's no artist (should be handled below by contributors.size test)
//        } catch(java.util.NoSuchElementException Ex) {
//          // ignore this exception, it means there's no artist for that album
//        }
       
        upnpAlbum.setId(objectID+"/"+releaseItem.getId());
        upnpAlbum.setClazz(new org.teleal.cling.support.model.DIDLObject.Class("object.container.album.musicAlbum"));
       
        if(contributors.size()>0) {
          upnpAlbum.setCreator(contributors.get(0).getName());
        } else {
          upnpAlbum.setCreator("unknown");
        }
       
        upnpAlbum.setTitle(releaseItem.getItem().getName());
        upnpAlbum.addProperty(new DIDLObject.Property.UPNP.ALBUM(upnpAlbum.getTitle()) );
        upnpAlbum.setDescription("aze");
        // <albumArtUri dlna:profileID="PNG_TN">
        // <albumArtUri dlna:profileID="JPEG_TN">
       
        upnpAlbum.setAlbumArtURIs(new URI[] { new URI(releaseItem.getImage().getUrl())} );
        Property<URI>[] albumArtUriProperties = upnpAlbum.getProperties(UPNP.ALBUM_ART_URI.class);
        for(Property<URI> uriProperty : albumArtUriProperties) {
          //DIDLObject.Property.DLNA.PROFILE_ID toto = new DIDLObject.Property.DLNA.PROFILE_ID();
          //toto.getValue().
          //DIDLAttribute tutu = new DIDLAttribute(DIDLObject.Property.DLNA, "dlna", "zeazé")
         
          // value for dlna:profileID attribute of upnp:albumArtURI element
          String upnpProfileID;
         
            if(uriProperty.getValue().toString().endsWith(".png")) {
              upnpProfileID = "PNG_TN";
            } else {
              // if extension isn't png, suppose it's JPEG (may be a bad guess)
              upnpProfileID = "JPEG_TN";
              // TODO: improve image entity to contain image type or enhance this code
              // to detect image format
            }
           
          uriProperty.addAttribute(
              new DIDLObject.Property.DLNA.PROFILE_ID(
                  new DIDLAttribute(
                  DIDLObject.Property.DLNA.NAMESPACE.URI,
                  "dlna",
                  upnpProfileID)
              ) 
          );         
        }
       
        // search for album genre
// commented for performance reason, should be uncommented or changed
// when performance problem is solved
//        List<String> albumGenres = new ArrayList<String>();
//        for(ResultItem<ClassificationEntity> classificationResult: classificationBrowseService.findChildren(Arrays.asList(releaseItem.getId()), null, 0, null, false).getItems() ) {
//          ClassificationEntity classification = classificationResult.getItem();
//          if(classification.getType().equals("genre")) {
//            albumGenres.add(classification.getName());
//          }
//        }

       
        // construct album genres from genre, style and moods classifications
        List<String> albumGenres = new ArrayList<String>();
        for(ResultItem<ClassificationEntity> classificationResult:
                classificationBrowseService.findChildren(
                  Arrays.asList(releaseItem.getId(),"Classification.genre"),
                    null, 0, null, false).getItems()
        ) {
          StringTokenizer sk = new StringTokenizer(classificationResult.getItem().getName(), ",");
          while(sk.hasMoreTokens() ) {
            String genre = sk.nextToken().trim();
            if(!albumGenres.contains(genre))
              albumGenres.add(genre);
          }
        }

        for(ResultItem<ClassificationEntity> classificationResult:
          classificationBrowseService.findChildren(
            Arrays.asList(releaseItem.getId(),"Classification.style"),
              null, 0, null, false).getItems()
        ) {
//            albumGenres.addAll( Arrays.asList(classificationResult.getItem().getName().split(" ")) );
          StringTokenizer sk = new StringTokenizer(classificationResult.getItem().getName(), ",");
          while(sk.hasMoreTokens() ) {
            String genre = sk.nextToken().trim();
            if(!albumGenres.contains(genre))
              albumGenres.add(genre);
          }
        }

        for(ResultItem<ClassificationEntity> classificationResult:
          classificationBrowseService.findChildren(
            Arrays.asList(releaseItem.getId(),"Classification.mood"),
              null, 0, null, false).getItems()
        ) {
//            albumGenres.add(classificationResult.getItem().getName());
            StringTokenizer sk = new StringTokenizer(classificationResult.getItem().getName(), ",");
            while(sk.hasMoreTokens() ) {
              String genre = sk.nextToken().trim();
              if(!albumGenres.contains(genre))
                albumGenres.add(genre);
            }           
        }
         
        if(albumGenres.size()>0) {
          upnpAlbum.setGenres(albumGenres.toArray(new String[0]));
        }
       
        // TODO: add childcount is asked for by the client parameters
        // before r839: upnpContainer.setChildCount(browseService.findChildren(objectID+"/"+releaseItem.getId(), null, null, false).getCount().intValue());
        // after  r839: upnpContainer.setChildCount(browseService.findChildren("upnp", artistItem.getId(), null, null, false).getCount().intValue());
View Full Code Here

TOP

Related Classes of org.teleal.cling.support.model.container.MusicAlbum

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.