org.fourthline.cling.support.model.Res Java Examples

The following examples show how to use org.fourthline.cling.support.model.Res. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentContainerActivity.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
private void playItem(Item item){
    if (item == null) return;

    Res res = item.getFirstResource();
    String uri = res.getValue();

    DIDLContent content = new DIDLContent();
    content.addItem(item);
    DIDLParser didlParser = new DIDLParser();
    String metadata = null;
    try {
        metadata = didlParser.generate(content);
    } catch (Exception e) {
        //ignore
    }
    //Log.d(TAG,"Item metadata:" + metadata);
    //Play on the selected device.
    PlaybackCommand.playNewItem(uri,metadata);
}
 
Example #2
Source File: DIDLParser.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    super.startElement(uri, localName, qName, attributes);

    if (!DIDLContent.NAMESPACE_URI.equals(uri)) return;

    if (localName.equals("res")) {

        Res res = createResource(attributes);
        if (res != null) {
            getInstance().addResource(res);
            createResHandler(res, this);
        }

    } else if (localName.equals("desc")) {

        DescMeta desc = createDescMeta(attributes);
        getInstance().addDescMetadata(desc);
        createDescMetaHandler(desc, this);

    }
}
 
Example #3
Source File: Utils.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public static String getRealImagePath(ContentItem paramContentItem) {
	int[] arrayOfInt = new int[paramContentItem.getItem().getResources()
			.size()];
	String str1 = "";
	int i = 0;
	// i = paramContentItem.getItem().getResources().size();
	// if (str1.equals(""))
	// return str1;
	if (((Res) paramContentItem.getItem().getResources().get(i)).getValue() != null) {
		String str2 = ((Res) paramContentItem.getItem().getResources()
				.get(i)).getResolution();
		if (str2 != null) {
			str1 = ((Res) paramContentItem.getItem().getResources().get(i))
					.getValue();
			String[] arrayOfString = str2.split("x");
			arrayOfInt[i] = (Integer.parseInt(arrayOfString[0]) * Integer
					.parseInt(arrayOfString[1]));
		}
	}
	// ++i;
	// str1 = ((Res) paramContentItem.getItem().getResources()
	// .get(getMaxID(arrayOfInt))).getValue();

	return str1;
}
 
Example #4
Source File: CustomContentDirectory.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
protected Res createResourceForSong(MediaFile song) {
    Player player = playerService.getGuestPlayer(null);

    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getBaseUrl() + "/ext/stream")
            .queryParam("id", song.getId())
            .queryParam("player", player.getId());

    if (song.isVideo()) {
        builder.queryParam("format", TranscodingService.FORMAT_RAW);
    }

    jwtSecurityService.addJWTToken(User.USERNAME_ANONYMOUS, builder);

    String url = builder.toUriString();

    String suffix = song.isVideo() ? FilenameUtils.getExtension(song.getPath()) : transcodingService.getSuffix(player, song, null);
    String mimeTypeString = StringUtil.getMimeType(suffix);
    MimeType mimeType = mimeTypeString == null ? null : MimeType.valueOf(mimeTypeString);

    Res res = new Res(mimeType, null, url);
    res.setDuration(formatDuration(song.getDuration()));
    return res;
}
 
Example #5
Source File: CustomContentDirectory.java    From airsonic with GNU General Public License v3.0 6 votes vote down vote up
protected Res createResourceForSong(MediaFile song) {
    Player player = playerService.getGuestPlayer(null);

    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getBaseUrl() + "/ext/stream")
            .queryParam("id", song.getId())
            .queryParam("player", player.getId());

    if (song.isVideo()) {
        builder.queryParam("format", TranscodingService.FORMAT_RAW);
    }

    jwtSecurityService.addJWTToken(builder);

    String url = builder.toUriString();

    String suffix = song.isVideo() ? FilenameUtils.getExtension(song.getPath()) : transcodingService.getSuffix(player, song, null);
    String mimeTypeString = StringUtil.getMimeType(suffix);
    MimeType mimeType = mimeTypeString == null ? null : MimeType.valueOf(mimeTypeString);

    Res res = new Res(mimeType, null, url);
    res.setDuration(formatDuration(song.getDurationSeconds()));
    return res;
}
 
Example #6
Source File: DIDLParser.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    super.startElement(uri, localName, qName, attributes);

    if (!DIDLContent.NAMESPACE_URI.equals(uri)) return;

    if (localName.equals("res")) {

        Res res = createResource(attributes);
        if (res != null) {
            getInstance().addResource(res);
            createResHandler(res, this);
        }

    } else if (localName.equals("desc")) {

        DescMeta desc = createDescMeta(attributes);
        getInstance().addDescMetadata(desc);
        createDescMetaHandler(desc, this);

    }
}
 
Example #7
Source File: MusicTrack.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public MusicTrack(String id, String parentID, String title, String creator, String album, PersonWithRole artist, Res... resource) {
    super(id, parentID, title, creator, resource);
    setClazz(CLASS);
    if (album != null)
        setAlbum(album);
    if (artist != null)
        addProperty(new UPNP.ARTIST(artist));
}
 
Example #8
Source File: Container.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public Container(String id, String parentID, String title, String creator, boolean restricted, WriteStatus writeStatus, Class clazz, List<Res> resources, List<Property> properties, List<DescMeta> descMetadata, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) {
    super(id, parentID, title, creator, restricted, writeStatus, clazz, resources, properties, descMetadata);
    this.childCount = childCount;
    this.searchable = searchable;
    this.createClasses = createClasses;
    this.searchClasses = searchClasses;
    this.items = items;
}
 
Example #9
Source File: DIDLParser.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    super.startElement(uri, localName, qName, attributes);

    if (!DIDLContent.NAMESPACE_URI.equals(uri)) return;

    if (localName.equals("item")) {

        Item item = createItem(attributes);
        getInstance().addItem(item);
        createItemHandler(item, this);

    } else if (localName.equals("desc")) {

        DescMeta desc = createDescMeta(attributes);
        getInstance().addDescMetadata(desc);
        createDescMetaHandler(desc, this);

    } else if (localName.equals("res")) {

        Res res = createResource(attributes);
        if (res != null) {
            getInstance().addResource(res);
            createResHandler(res, this);
        }

    }

    // We do NOT support recursive container embedded in container! The schema allows it
    // but the spec doesn't:
    //
    // Section 2.8.3: Incremental navigation i.e. the full hierarchy is never returned
    // in one call since this is likely to flood the resources available to the control
    // point (memory, network bandwidth, etc.).
}
 
Example #10
Source File: MusicTrack.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public MusicTrack(String id, String parentID, String title, String creator, String album, PersonWithRole artist, Res... resource) {
    super(id, parentID, title, creator, resource);
    setClazz(CLASS);
    if (album != null)
        setAlbum(album);
    if (artist != null)
        addProperty(new UPNP.ARTIST(artist));
}
 
Example #11
Source File: AudioBook.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public AudioBook(String id, String parentID, String title, String creator, Person producer, Person contributor, String date, Res... resource) {
    super(id, parentID, title, creator, resource);
    setClazz(CLASS);
    if (producer != null)
        addProperty(new UPNP.PRODUCER(producer));
    if (contributor != null)
        addProperty(new DC.CONTRIBUTOR(contributor));
    if (date != null)
        setDate(date);
}
 
Example #12
Source File: DIDLParser.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
protected void generateResource(Res resource, Document descriptor, Element parent) {

        if (resource.getValue() == null) {
            throw new RuntimeException("Missing resource URI value" + resource);
        }
        if (resource.getProtocolInfo() == null) {
            throw new RuntimeException("Missing resource protocol info: " + resource);
        }

        Element resourceElement = appendNewElement(descriptor, parent, "res", resource.getValue());
        resourceElement.setAttribute("protocolInfo", resource.getProtocolInfo().toString());
        if (resource.getImportUri() != null)
            resourceElement.setAttribute("importUri", resource.getImportUri().toString());
        if (resource.getSize() != null)
            resourceElement.setAttribute("size", resource.getSize().toString());
        if (resource.getDuration() != null)
            resourceElement.setAttribute("duration", resource.getDuration());
        if (resource.getBitrate() != null)
            resourceElement.setAttribute("bitrate", resource.getBitrate().toString());
        if (resource.getSampleFrequency() != null)
            resourceElement.setAttribute("sampleFrequency", resource.getSampleFrequency().toString());
        if (resource.getBitsPerSample() != null)
            resourceElement.setAttribute("bitsPerSample", resource.getBitsPerSample().toString());
        if (resource.getNrAudioChannels() != null)
            resourceElement.setAttribute("nrAudioChannels", resource.getNrAudioChannels().toString());
        if (resource.getColorDepth() != null)
            resourceElement.setAttribute("colorDepth", resource.getColorDepth().toString());
        if (resource.getProtection() != null)
            resourceElement.setAttribute("protection", resource.getProtection());
        if (resource.getResolution() != null)
            resourceElement.setAttribute("resolution", resource.getResolution());
    }
 
Example #13
Source File: DIDLParser.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    super.startElement(uri, localName, qName, attributes);

    if (!DIDLContent.NAMESPACE_URI.equals(uri)) return;

    if (localName.equals("item")) {

        Item item = createItem(attributes);
        getInstance().addItem(item);
        createItemHandler(item, this);

    } else if (localName.equals("desc")) {

        DescMeta desc = createDescMeta(attributes);
        getInstance().addDescMetadata(desc);
        createDescMetaHandler(desc, this);

    } else if (localName.equals("res")) {

        Res res = createResource(attributes);
        if (res != null) {
            getInstance().addResource(res);
            createResHandler(res, this);
        }

    }

    // We do NOT support recursive container embedded in container! The schema allows it
    // but the spec doesn't:
    //
    // Section 2.8.3: Incremental navigation i.e. the full hierarchy is never returned
    // in one call since this is likely to flood the resources available to the control
    // point (memory, network bandwidth, etc.).
}
 
Example #14
Source File: DIDLParser.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected void generateResource(Res resource, Document descriptor, Element parent) {

        if (resource.getValue() == null) {
            throw new RuntimeException("Missing resource URI value" + resource);
        }
        if (resource.getProtocolInfo() == null) {
            throw new RuntimeException("Missing resource protocol info: " + resource);
        }

        Element resourceElement = appendNewElement(descriptor, parent, "res", resource.getValue());
        resourceElement.setAttribute("protocolInfo", resource.getProtocolInfo().toString());
        if (resource.getImportUri() != null)
            resourceElement.setAttribute("importUri", resource.getImportUri().toString());
        if (resource.getSize() != null)
            resourceElement.setAttribute("size", resource.getSize().toString());
        if (resource.getDuration() != null)
            resourceElement.setAttribute("duration", resource.getDuration());
        if (resource.getBitrate() != null)
            resourceElement.setAttribute("bitrate", resource.getBitrate().toString());
        if (resource.getSampleFrequency() != null)
            resourceElement.setAttribute("sampleFrequency", resource.getSampleFrequency().toString());
        if (resource.getBitsPerSample() != null)
            resourceElement.setAttribute("bitsPerSample", resource.getBitsPerSample().toString());
        if (resource.getNrAudioChannels() != null)
            resourceElement.setAttribute("nrAudioChannels", resource.getNrAudioChannels().toString());
        if (resource.getColorDepth() != null)
            resourceElement.setAttribute("colorDepth", resource.getColorDepth().toString());
        if (resource.getProtection() != null)
            resourceElement.setAttribute("protection", resource.getProtection());
        if (resource.getResolution() != null)
            resourceElement.setAttribute("resolution", resource.getResolution());
    }
 
Example #15
Source File: UpnpControlSet.java    From HPlayer with Apache License 2.0 5 votes vote down vote up
public void setAVTransportURI(String url, int schedule, String title, String id, String creator, String parentID) {
    alreadyPlay = false;
    currentPosition = schedule;
    //TODO 此处有问题 究竟如何才是正确的DLNA推屏数据?
    DIDLParser didlParser = new DIDLParser();
    DIDLContent content = new DIDLContent();
    Res res = new Res();
    Movie movie = new Movie(id, parentID, title, creator, res);
    content.addItem(movie);
    String didlString = "";
    try {
        didlString = didlParser.generate(content);
    } catch (Exception e) {
        e.printStackTrace();
    }
    ActionCallback setAVTransport = new SetAVTransportURI(
            avTransportService, url, didlString) {

        @Override
        public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
            onFailureCallBack(SET_AVTRANSPORT, arg2);
        }

        @Override
        public void success(ActionInvocation invocation) {
            onVideoPlay();

            // TODO 究竟如何将当前进度一起推送过去,让播放器播放时自动跳转?
            // TODO DLNA 是否支持这个尚不清楚
            getDMRTransportInfo();// 远程渲染器播放准备完成不会主动告诉终端,需获取状态来做进度推送

            onSuccessCallBack(SET_AVTRANSPORT);
        }
    };
    mUpnpService.getControlPoint().execute(setAVTransport);
}
 
Example #16
Source File: SubsonicContentDirectory.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
protected Res createResourceForSong(MediaFile song) {
    Player player = playerService.getGuestPlayer(null);
    String url = getBaseUrl() + "stream?id=" + song.getId() + "&player=" + player.getId();
    if (song.isVideo()) {
        url += "&format=" + TranscodingService.FORMAT_RAW;
    }

    String suffix = song.isVideo() ? FilenameUtils.getExtension(song.getPath()) : transcodingService.getSuffix(player, song, null);
    String mimeTypeString = StringUtil.getMimeType(suffix);
    MimeType mimeType = mimeTypeString == null ? null : MimeType.valueOf(mimeTypeString);

    Res res = new Res(mimeType, null, url);
    res.setDuration(formatDuration(song.getDurationSeconds()));
    return res;
}
 
Example #17
Source File: AudioBook.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public AudioBook(String id, String parentID, String title, String creator, Person producer, Person contributor, String date, Res... resource) {
    super(id, parentID, title, creator, resource);
    setClazz(CLASS);
    if (producer != null)
        addProperty(new UPNP.PRODUCER(producer));
    if (contributor != null)
        addProperty(new DC.CONTRIBUTOR(contributor));
    if (date != null)
        setDate(date);
}
 
Example #18
Source File: MediaResourceDao.java    From BeyondUPnP with Apache License 2.0 5 votes vote down vote up
public static List<Item> getAudioList(String serverUrl, String parentId) {
    List<Item> items = new ArrayList<>();

    //Query all track,add to items
    Cursor c = BeyondApplication.getApplication().getContentResolver()
            .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.TITLE);
    c.moveToFirst();
    while (!c.isAfterLast()) {
        long id = c.getLong(c.getColumnIndex(MediaStore.Audio.Media._ID));
        String title = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
        String creator = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
        String album = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));

        String data = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
        //Remove SDCard path
        data = data.replaceFirst(storageDir, "");
        //Replace file name by "id.ext"
        String fileName = data.substring(data.lastIndexOf(File.separator));
        String ext = fileName.substring(fileName.lastIndexOf("."));
        data = data.replace(fileName, File.separator + id + ext);

        String mimeType = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));
        long size = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));
        long duration = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
        //Get duration string
        String durationStr = ModelUtil.toTimeString(duration);

        //Compose audio url
        String url = serverUrl + File.separator + "audio" + File.separator + data;
        Res res = new Res(mimeType, size, durationStr, null, url);

        items.add(new MusicTrack(String.valueOf(id), parentId, title, creator, album, new PersonWithRole(creator), res));

        c.moveToNext();
    }

    return items;
}
 
Example #19
Source File: Container.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public Container(String id, String parentID, String title, String creator, boolean restricted, WriteStatus writeStatus, Class clazz, List<Res> resources, List<Property> properties, List<DescMeta> descMetadata, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) {
    super(id, parentID, title, creator, restricted, writeStatus, clazz, resources, properties, descMetadata);
    this.childCount = childCount;
    this.searchable = searchable;
    this.createClasses = createClasses;
    this.searchClasses = searchClasses;
    this.items = items;
}
 
Example #20
Source File: MediaResourceDao.java    From BeyondUPnP with Apache License 2.0 5 votes vote down vote up
public static List<Item> getVideoList(String serverUrl, String parentId) {
    List<Item> items = new ArrayList<>();

    Cursor c = BeyondApplication.getApplication().getContentResolver()
            .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Video.Media.TITLE);
    c.moveToFirst();
    while (!c.isAfterLast()) {
        long id = c.getLong(c.getColumnIndex(MediaStore.Audio.Media._ID));
        String title = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
        String creator = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST));

        String data = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
        //Remove SDCard path
        data = data.replaceFirst(storageDir, "");
        //Replace file name by "id.ext"
        String fileName = data.substring(data.lastIndexOf(File.separator));
        String ext = fileName.substring(fileName.lastIndexOf("."));
        data = data.replace(fileName, File.separator + id + ext);

        String mimeType = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
        long size = c.getLong(c.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
        long duration = c.getLong(c.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
        //Get duration string
        String durationStr = ModelUtil.toTimeString(duration);

        //Compose audio url
        String url = serverUrl + File.separator + "video" + File.separator + data;
        Res res = new Res(mimeType, size, durationStr, null, url);

        items.add(new Movie(String.valueOf(id), parentId, title, creator, res));

        c.moveToNext();
    }

    return items;
}
 
Example #21
Source File: ImageItem.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ImageItem(String id, Container parent, String title, String creator, Res... resource) {
    this(id, parent.getId(), title, creator, resource);
}
 
Example #22
Source File: TextItem.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public TextItem(String id, Container parent, String title, String creator, Res... resource) {
    this(id, parent.getId(), title, creator, resource);
}
 
Example #23
Source File: TextItem.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public TextItem(String id, String parentID, String title, String creator, Res... resource) {
    super(id, parentID, title, creator, CLASS);
    if (resource != null) {
        getResources().addAll(Arrays.asList(resource));
    }
}
 
Example #24
Source File: VideoBroadcast.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public VideoBroadcast(String id, String parentID, String title, String creator, Res... resource) {
    super(id, parentID, title, creator, resource);
    setClazz(CLASS);
}
 
Example #25
Source File: Item.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public Item(String id, String parentID, String title, String creator, boolean restricted, WriteStatus writeStatus, Class clazz, List<Res> resources, List<Property> properties, List<DescMeta> descMetadata, String refID) {
    super(id, parentID, title, creator, restricted, writeStatus, clazz, resources, properties, descMetadata);
    this.refID = refID;
}
 
Example #26
Source File: Item.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public Item(String id, String parentID, String title, String creator, boolean restricted, WriteStatus writeStatus, Class clazz, List<Res> resources, List<Property> properties, List<DescMeta> descMetadata) {
    super(id, parentID, title, creator, restricted, writeStatus, clazz, resources, properties, descMetadata);
}
 
Example #27
Source File: AudioBook.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public AudioBook(String id, Container parent, String title, String creator, String producer, String contributor, String date, Res... resource) {
    this(id, parent.getId(), title, creator, new Person(producer), new Person(contributor), date, resource);
}
 
Example #28
Source File: Movie.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public Movie(String id, String parentID, String title, String creator, Res... resource) {
    super(id, parentID, title, creator, resource);
    setClazz(CLASS);
}
 
Example #29
Source File: PlaylistItem.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public PlaylistItem(String id, String parentID, String title, String creator, Res... resource) {
    super(id, parentID, title, creator, CLASS);
    if (resource != null) {
        getResources().addAll(Arrays.asList(resource));
    }
}
 
Example #30
Source File: AudioBook.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public AudioBook(String id, Container parent, String title, String creator, Res... resource) {
    this(id, parent.getId(), title, creator, null, null, null, resource);
}