Java Code Examples for org.fourthline.cling.support.model.Res#setDuration()

The following examples show how to use org.fourthline.cling.support.model.Res#setDuration() . 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: 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 2
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 3
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 4
Source File: DIDLParser.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
protected Res createResource(Attributes attributes) {
    Res res = new Res();

    if (attributes.getValue("importUri") != null)
        res.setImportUri(URI.create(attributes.getValue("importUri")));

    try {
        res.setProtocolInfo(
                new ProtocolInfo(attributes.getValue("protocolInfo"))
        );
    } catch (InvalidValueException ex) {
        log.warning("In DIDL content, invalid resource protocol info: " + Exceptions.unwrap(ex));
        return null;
    }

    if (attributes.getValue("size") != null)
        res.setSize(Long.valueOf(attributes.getValue("size")));

    if (attributes.getValue("duration") != null)
        res.setDuration(attributes.getValue("duration"));

    if (attributes.getValue("bitrate") != null)
        res.setBitrate(Long.valueOf(attributes.getValue("bitrate")));

    if (attributes.getValue("sampleFrequency") != null)
        res.setSampleFrequency(Long.valueOf(attributes.getValue("sampleFrequency")));

    if (attributes.getValue("bitsPerSample") != null)
        res.setBitsPerSample(Long.valueOf(attributes.getValue("bitsPerSample")));

    if (attributes.getValue("nrAudioChannels") != null)
        res.setNrAudioChannels(Long.valueOf(attributes.getValue("nrAudioChannels")));

    if (attributes.getValue("colorDepth") != null)
        res.setColorDepth(Long.valueOf(attributes.getValue("colorDepth")));

    if (attributes.getValue("protection") != null)
        res.setProtection(attributes.getValue("protection"));

    if (attributes.getValue("resolution") != null)
        res.setResolution(attributes.getValue("resolution"));

    return res;
}
 
Example 5
Source File: GenerateContentTask.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
/**
     * 添加视频
     */
    private void addVideoContent(Context context, ContentNode rootNode) {

        Container videoContainer = new Container();
        videoContainer.setClazz(new DIDLObject.Class("object.container"));
        videoContainer.setId(ContentTree.VIDEO_ID);
        videoContainer.setParentID(ContentTree.ROOT_ID);
        videoContainer.setTitle("Videos");
        videoContainer.setRestricted(true);
        videoContainer.setWriteStatus(WriteStatus.NOT_WRITABLE);
        videoContainer.setChildCount(0);

        rootNode.getContainer().addContainer(videoContainer);
        rootNode.getContainer().setChildCount(
                rootNode.getContainer().getChildCount() + 1);
        ContentTree.addNode(ContentTree.VIDEO_ID, new ContentNode(
                ContentTree.VIDEO_ID, videoContainer));

        Cursor cursor = context.getContentResolver()
                .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                        null, null, null, null);
        if (cursor == null) {
            return;
        }
        while (cursor.moveToNext()) {
            String id = ContentTree.VIDEO_PREFIX
                    + cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media._ID));
            String title = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
            String creator = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST));
            String filePath = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
            String mimeType = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
            long size = cursor.getLong(cursor
                    .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
            long duration = cursor.getLong(cursor
                    .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
            String resolution = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Video.Media.RESOLUTION));
            Res res = new Res(new MimeType(mimeType.substring(0, mimeType.indexOf('/')),
                    mimeType.substring(mimeType.indexOf('/') + 1)), size,
                    "http://" + address + "/" + id);
            res.setDuration(duration / (1000 * 60 * 60) + ":"
                    + (duration % (1000 * 60 * 60)) / (1000 * 60) + ":"
                    + (duration % (1000 * 60)) / 1000);
            res.setResolution(resolution);

            VideoItem videoItem = new VideoItem(id, ContentTree.VIDEO_ID, title, creator, res);
            videoContainer.addItem(videoItem);
            videoContainer.setChildCount(videoContainer.getChildCount() + 1);
            ContentTree.addNode(id, new ContentNode(id, videoItem, filePath));

//            Log.d(TAG, "added video item " + title + "from " + filePath);
        }

        cursor.close();
    }
 
Example 6
Source File: GenerateContentTask.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
/**
     * 添加音频
     */
    private void addAudioContent(Context context, ContentNode rootNode) {

        Container audioContainer = new Container(ContentTree.AUDIO_ID,
                ContentTree.ROOT_ID, "Audios", "HPlayer MediaServer",
                new DIDLObject.Class("object.container"), 0);
        audioContainer.setRestricted(true);
        audioContainer.setWriteStatus(WriteStatus.NOT_WRITABLE);

        rootNode.getContainer().addContainer(audioContainer);
        rootNode.getContainer().setChildCount(
                rootNode.getContainer().getChildCount() + 1);
        ContentTree.addNode(ContentTree.AUDIO_ID, new ContentNode(
                ContentTree.AUDIO_ID, audioContainer));

        Cursor cursor = context.getContentResolver()
                .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                        null, null, null, null);
        if (cursor == null) {
            return;
        }

        while (cursor.moveToNext()) {
            String id = ContentTree.AUDIO_PREFIX
                    + cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
            String title = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
            String creator = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
            String filePath = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
            String mimeType = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));
            long size = cursor.getLong(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));
            long duration = cursor.getLong(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
            String album = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
            Res res = new Res(new MimeType(mimeType.substring(0, mimeType.indexOf('/')),
                    mimeType.substring(mimeType.indexOf('/') + 1)), size,
                    "http://" + address + "/" + id);
            res.setDuration(duration / (1000 * 60 * 60) + ":"
                    + (duration % (1000 * 60 * 60)) / (1000 * 60) + ":"
                    + (duration % (1000 * 60)) / 1000);

            // Music Track must have `artist' with role field, or
            // DIDLParser().generate(didl) will throw nullpointException
            MusicTrack musicTrack = new MusicTrack(id,
                    ContentTree.AUDIO_ID, title, creator, album,
                    new PersonWithRole(creator, "Performer"), res);
            audioContainer.addItem(musicTrack);
            audioContainer.setChildCount(audioContainer.getChildCount() + 1);
            ContentTree.addNode(id, new ContentNode(id, musicTrack, filePath));

//            Log.d(TAG, "added audio item " + title + "from " + filePath);
        }

        cursor.close();
    }
 
Example 7
Source File: DIDLParser.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
protected Res createResource(Attributes attributes) {
    Res res = new Res();

    if (attributes.getValue("importUri") != null)
        res.setImportUri(URI.create(attributes.getValue("importUri")));

    try {
        res.setProtocolInfo(
                new ProtocolInfo(attributes.getValue("protocolInfo"))
        );
    } catch (InvalidValueException ex) {
        log.warning("In DIDL content, invalid resource protocol info: " + Exceptions.unwrap(ex));
        return null;
    }

    if (attributes.getValue("size") != null)
        res.setSize(Long.valueOf(attributes.getValue("size")));

    if (attributes.getValue("duration") != null)
        res.setDuration(attributes.getValue("duration"));

    if (attributes.getValue("bitrate") != null)
        res.setBitrate(Long.valueOf(attributes.getValue("bitrate")));

    if (attributes.getValue("sampleFrequency") != null)
        res.setSampleFrequency(Long.valueOf(attributes.getValue("sampleFrequency")));

    if (attributes.getValue("bitsPerSample") != null)
        res.setBitsPerSample(Long.valueOf(attributes.getValue("bitsPerSample")));

    if (attributes.getValue("nrAudioChannels") != null)
        res.setNrAudioChannels(Long.valueOf(attributes.getValue("nrAudioChannels")));

    if (attributes.getValue("colorDepth") != null)
        res.setColorDepth(Long.valueOf(attributes.getValue("colorDepth")));

    if (attributes.getValue("protection") != null)
        res.setProtection(attributes.getValue("protection"));

    if (attributes.getValue("resolution") != null)
        res.setResolution(attributes.getValue("resolution"));

    return res;
}