Search in sources :

Example 1 with Movie

use of org.fourthline.cling.support.model.item.Movie 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)

Aggregations

Cursor (android.database.Cursor)1 ArrayList (java.util.ArrayList)1 Res (org.fourthline.cling.support.model.Res)1 Item (org.fourthline.cling.support.model.item.Item)1 Movie (org.fourthline.cling.support.model.item.Movie)1