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 Project: airsonic-advanced   Author: airsonic-advanced   File: CustomContentDirectory.java    License: 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 #2
Source Project: DroidDLNA   Author: offbye   File: Utils.java    License: 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 #3
Source Project: TVRemoteIME   Author: kingthy   File: DIDLParser.java    License: 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 #4
Source Project: airsonic   Author: airsonic   File: CustomContentDirectory.java    License: 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 #5
Source Project: BeyondUPnP   Author: kevinshine   File: ContentContainerActivity.java    License: 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 #6
Source Project: DroidDLNA   Author: offbye   File: DIDLParser.java    License: 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 #7
Source Project: TVRemoteIME   Author: kingthy   File: AudioBook.java    License: 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 #8
Source Project: TVRemoteIME   Author: kingthy   File: MusicTrack.java    License: 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 #9
Source Project: TVRemoteIME   Author: kingthy   File: Container.java    License: 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 #10
Source Project: DroidDLNA   Author: offbye   File: DIDLParser.java    License: 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 #11
Source Project: TVRemoteIME   Author: kingthy   File: DIDLParser.java    License: 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 #12
Source Project: TVRemoteIME   Author: kingthy   File: DIDLParser.java    License: 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 #13
Source Project: DroidDLNA   Author: offbye   File: DIDLParser.java    License: 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 #14
Source Project: HPlayer   Author: hezhubo   File: UpnpControlSet.java    License: 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 #15
Source Project: subsonic   Author: sindremehus   File: SubsonicContentDirectory.java    License: 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 #16
Source Project: BeyondUPnP   Author: kevinshine   File: MediaResourceDao.java    License: 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 #17
Source Project: BeyondUPnP   Author: kevinshine   File: MediaResourceDao.java    License: 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 #18
Source Project: DroidDLNA   Author: offbye   File: AudioBook.java    License: 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 #19
Source Project: DroidDLNA   Author: offbye   File: MusicTrack.java    License: 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 #20
Source Project: DroidDLNA   Author: offbye   File: Container.java    License: 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 #21
Source Project: TVRemoteIME   Author: kingthy   File: Movie.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Movie(String id, Container parent, String title, String creator, Res... resource) {
    this(id, parent.getId(), title, creator, resource);
}
 
Example #22
Source Project: TVRemoteIME   Author: kingthy   File: Movie.java    License: GNU General Public License v2.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 #23
Source Project: TVRemoteIME   Author: kingthy   File: AudioBook.java    License: GNU General Public License v2.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);
}
 
Example #24
Source Project: TVRemoteIME   Author: kingthy   File: AudioBook.java    License: GNU General Public License v2.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 #25
Source Project: TVRemoteIME   Author: kingthy   File: Item.java    License: GNU General Public License v2.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 #26
Source Project: TVRemoteIME   Author: kingthy   File: Item.java    License: GNU General Public License v2.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 #27
Source Project: TVRemoteIME   Author: kingthy   File: VideoItem.java    License: GNU General Public License v2.0 4 votes vote down vote up
public VideoItem(String id, Container parent, String title, String creator, Res... resource) {
    this(id, parent.getId(), title, creator, resource);
}
 
Example #28
Source Project: TVRemoteIME   Author: kingthy   File: VideoItem.java    License: GNU General Public License v2.0 4 votes vote down vote up
public VideoItem(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 #29
Source Project: TVRemoteIME   Author: kingthy   File: PlaylistItem.java    License: GNU General Public License v2.0 4 votes vote down vote up
public PlaylistItem(String id, Container parent, String title, String creator, Res... resource) {
    this(id, parent.getId(), title, creator, resource);
}
 
Example #30
Source Project: TVRemoteIME   Author: kingthy   File: PlaylistItem.java    License: GNU General Public License v2.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));
    }
}