Package org.teleal.cling.support.model.item

Examples of org.teleal.cling.support.model.item.MusicTrack


     * @param filters      list of elements to be returned
     * @return
     */
    private MusicTrack getUpnpMusicTrackFromSmdTrackEntity(ResultItem<TrackEntity> trackResultItem, String parentId, List<String> filters) {

      MusicTrack upnpTrack = new MusicTrack();
      TrackEntity trackItem = trackResultItem.getItem();
     
    // Mandatory elements:
    upnpTrack.setId(parentId+"/"+trackResultItem.getId());
    upnpTrack.setRefID(trackResultItem.getId());
    upnpTrack.setTitle(trackResultItem.getName());


    if(wantedProperty("dc:creator", filters)) {
      try {
        upnpTrack.setCreator(trackItem.getRecording().getContributors().iterator().next().getArtist().getName());
      }catch (Exception NoSuchElementException) {
        upnpTrack.setCreator("unknown");
      }
    }
    if(wantedProperty("upnp:album", filters)) {   
      upnpTrack.setAlbum(trackItem.getRelease().getName());
    }
    if(wantedProperty("upnp:originalTrackNumber", filters)) {
      upnpTrack.setOriginalTrackNumber(trackItem.getNumber());
    }
    if(wantedProperty("dc:date", filters)) {
      // TODO: verify date nullity
      // upnpTrack.setDate(trackItem.getRelease().getDate().toString());
    }
    if(wantedProperty("upnp:artists", filters)) {
      //upnpTrack.setArtists()
      List<PersonWithRole> contributors = new ArrayList<PersonWithRole>();     
   
      for(Contributor contributor: trackItem.getRecording().getContributors()) {
        contributors.add(new PersonWithRole(contributor.getArtist().getName(),
            contributor.getType()));
       
      }
      upnpTrack.setArtists(contributors.toArray(new PersonWithRole[0]));
    }
   
    if(wantedProperty("res", filters)) {   
      Res upnpResource = new Res();
      upnpResource.setProtocolInfo(new ProtocolInfo("*:*:*:*"));
      if(trackResultItem.getItem().getPlayableElements().size() != 1 ) {
        // TODO: handle track items with multiple playable elements
        System.err.println("Track "+trackResultItem.getName()+" ("+trackResultItem.getId()+") has "+
            trackItem.getPlayableElements().size()+
            " playable elements item, no support yet for ");
      }
      upnpResource.setValue(trackItem.getPlayableElements().iterator().next().getUri());
      upnpTrack.addResource(upnpResource);
    }
    return upnpTrack;

// unnecessary, initialized by constructor
//    upnpTrack.setClazz(new org.teleal.cling.support.model.DIDLObject.Class("object.item.audioItem.musicTrack"));
View Full Code Here


//        System.err.println(smdTrack.getId());
//        if("9709128e-b607-4069-a101-ce76171c06dd".equals(smdTrack.getId())) {
//          System.err.println("bad element");
//        }
         
        MusicTrack upnpTrack = new org.teleal.cling.support.model.item.MusicTrack();
        Res upnpResource = new Res();
        List<PersonWithRole> contributors = new ArrayList<PersonWithRole>()

        upnpTrack.setId(smdTrack.getId());
        upnpTrack.setParentID(smdTrack.getRelease().getId());
        upnpTrack.setClazz(new org.teleal.cling.support.model.DIDLObject.Class("object.item.audioItem.musicTrack"));
        upnpTrack.setTitle(smdTrack.getRecording().getWorks().iterator().next().getName());
        //work name used instead of trackname... TODO: check which is better / always working (trackname returns url encoded string) 
        //        .setTitle(trackItem.getName());

        if(smdTrack.getRecording().getContributors().size() > 0 ) {
          upnpTrack.setCreator(smdTrack.getRecording().getContributors().iterator().next().getArtist().getName());
        } else {
          upnpTrack.setCreator("no artist");
        }
        upnpTrack.setAlbum(smdTrack.getRelease().getName());
       
        for(Contributor contributor: smdTrack.getRecording().getContributors()) {
          contributors.add(new PersonWithRole(contributor.getArtist().getName(),
              contributor.getType()));
        }
        upnpTrack.setArtists(contributors.toArray(new PersonWithRole[0]));
       
        upnpResource.setProtocolInfo(new ProtocolInfo("*:*:*:*"));
        if(smdTrack.getPlayableElements().size() != 1 ) {
          // TODO: handle track items with multiple playable elements
          System.err.println("Track "+smdTrack+" ("+smdTrack.getId()+") has "+
              smdTrack.getPlayableElements().size()+
              " playable elements item, no support yet for ");
        }
        upnpResource.setValue(smdTrack.getPlayableElements().iterator().next().getUri());
        upnpTrack.addResource(upnpResource);
        didl.addItem(upnpTrack);
      }
      try {
        return new BrowseResult(new DIDLParser().generate(didl), searchResult.getItems().size(), searchResult.getCount().intValue());
      } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.teleal.cling.support.model.item.MusicTrack

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.