Search in sources :

Example 1 with Res

use of org.fourthline.cling.support.model.Res in project BeyondUPnP by kevinshine.

the class MediaResourceDao method getAudioList.

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;
}
Also used : Item(org.fourthline.cling.support.model.item.Item) Res(org.fourthline.cling.support.model.Res) MusicTrack(org.fourthline.cling.support.model.item.MusicTrack) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) PersonWithRole(org.fourthline.cling.support.model.PersonWithRole)

Example 2 with Res

use of org.fourthline.cling.support.model.Res in project BeyondUPnP by kevinshine.

the class ContentContainerActivity method addToPlaylist.

private void addToPlaylist(Item item) {
    if (item == null)
        return;
    Res res = item.getFirstResource();
    String uri = res.getValue();
    //Parse content.
    DIDLContent content = new DIDLContent();
    content.addItem(item);
    DIDLParser didlParser = new DIDLParser();
    String metadata = null;
    try {
        //Generate track metadata.
        metadata = didlParser.generate(content);
    } catch (Exception e) {
    //ignore
    }
    String albumUri = null;
    try {
        for (DIDLObject.Property property : item.getProperties()) {
            if (property instanceof DIDLObject.Property.UPNP.ALBUM_ART_URI) {
                albumUri = ((DIDLObject.Property.UPNP.ALBUM_ART_URI) property).getValue().toString();
            }
        }
    } catch (Exception e) {
    //ignore
    }
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(item.getCreator());
    stringBuilder.append(item.getTitle());
    stringBuilder.append(res.getSize());
    //Create md5 code
    String md5 = null;
    try {
        md5 = MD5.createMD5(stringBuilder.toString());
    } catch (NoSuchAlgorithmException e) {
        md5 = null;
    }
    ContentValues values = new ContentValues();
    values.put(PlaylistItem.ITEM_TITLE, item.getTitle());
    values.put(PlaylistItem.ITEM_URI, uri);
    values.put(PlaylistItem.ITEM_THUMB, albumUri);
    values.put(PlaylistItem.ITEM_METADATA, metadata);
    values.put(PlaylistItem.ITEM_DATE, System.currentTimeMillis());
    values.put(PlaylistItem.ITEM_VERIFICATION_CODE, md5);
    getContentResolver().insert(PlaylistItem.CONTENT_URI, values);
}
Also used : ContentValues(android.content.ContentValues) Res(org.fourthline.cling.support.model.Res) DIDLParser(org.fourthline.cling.support.contentdirectory.DIDLParser) DIDLObject(org.fourthline.cling.support.model.DIDLObject) DIDLContent(org.fourthline.cling.support.model.DIDLContent) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 3 with Res

use of org.fourthline.cling.support.model.Res in project BeyondUPnP by kevinshine.

the class ContentContainerActivity method playItem.

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);
}
Also used : Res(org.fourthline.cling.support.model.Res) DIDLParser(org.fourthline.cling.support.contentdirectory.DIDLParser) DIDLContent(org.fourthline.cling.support.model.DIDLContent) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 4 with Res

use of org.fourthline.cling.support.model.Res in project BeyondUPnP by kevinshine.

the class MediaResourceDao method getVideoList.

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;
}
Also used : Item(org.fourthline.cling.support.model.item.Item) Res(org.fourthline.cling.support.model.Res) Movie(org.fourthline.cling.support.model.item.Movie) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 5 with Res

use of org.fourthline.cling.support.model.Res in project libresonic by Libresonic.

the class LibresonicContentDirectory method createResourceForSong.

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;
}
Also used : Res(org.fourthline.cling.support.model.Res) Player(org.libresonic.player.domain.Player) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MimeType(org.seamless.util.MimeType)

Aggregations

Res (org.fourthline.cling.support.model.Res)5 Cursor (android.database.Cursor)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ArrayList (java.util.ArrayList)2 DIDLParser (org.fourthline.cling.support.contentdirectory.DIDLParser)2 DIDLContent (org.fourthline.cling.support.model.DIDLContent)2 Item (org.fourthline.cling.support.model.item.Item)2 ContentValues (android.content.ContentValues)1 DIDLObject (org.fourthline.cling.support.model.DIDLObject)1 PersonWithRole (org.fourthline.cling.support.model.PersonWithRole)1 Movie (org.fourthline.cling.support.model.item.Movie)1 MusicTrack (org.fourthline.cling.support.model.item.MusicTrack)1 Player (org.libresonic.player.domain.Player)1 MimeType (org.seamless.util.MimeType)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1