Search in sources :

Example 1 with Item

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

the class ContentContainerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview);
    mObjectId = getIntent().getStringExtra(OBJECT_ID_TAG);
    mIdentifierString = getIntent().getStringExtra(IDENTIFIER_STRING_TAG);
    String title = getIntent().getStringExtra(CONTENT_CONTAINER_TITLE);
    //Display container title.
    if (title != null) {
        setTitle(title);
    } else {
        setTitle("");
    }
    mDidlObjectAdapter = new DIDLObjectAdapter(ContentContainerActivity.this);
    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(mDidlObjectAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DIDLObject didlObject = mDidlObjectAdapter.getItem(position);
            if (didlObject instanceof Container) {
                Intent intent = new Intent(ContentContainerActivity.this, ContentContainerActivity.class);
                intent.putExtra(ContentContainerActivity.OBJECT_ID_TAG, didlObject.getId());
                intent.putExtra(ContentContainerActivity.IDENTIFIER_STRING_TAG, mIdentifierString);
                intent.putExtra(ContentContainerActivity.CONTENT_CONTAINER_TITLE, didlObject.getTitle());
                startActivity(intent);
            } else if (didlObject instanceof Item) {
                Item item = (Item) didlObject;
                playItem(item);
            }
        }
    });
    loadContent();
}
Also used : Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) MenuItem(android.view.MenuItem) PlaylistItem(com.kevinshen.beyondupnp.database.BeyondUpnpContract.PlaylistItem) Item(org.fourthline.cling.support.model.item.Item) Container(org.fourthline.cling.support.model.container.Container) ListView(android.widget.ListView) DIDLObject(org.fourthline.cling.support.model.DIDLObject) AdapterView(android.widget.AdapterView)

Example 2 with Item

use of org.fourthline.cling.support.model.item.Item 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 3 with Item

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

the class BeyondContentDirectoryService method browse.

@Override
public BrowseResult browse(String objectID, BrowseFlag browseFlag, String filter, long firstResult, long maxResults, SortCriterion[] orderby) throws ContentDirectoryException {
    String address = Utils.getIPAddress(true);
    String serverUrl = "http://" + address + ":" + JettyResourceServer.JETTY_SERVER_PORT;
    //Create container by id
    Container resultBean = ContainerFactory.createContainer(objectID, serverUrl);
    DIDLContent content = new DIDLContent();
    for (Container c : resultBean.getContainers()) content.addContainer(c);
    for (Item item : resultBean.getItems()) content.addItem(item);
    int count = resultBean.getChildCount();
    String contentModel = "";
    try {
        contentModel = new DIDLParser().generate(content);
    } catch (Exception e) {
        throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, e.toString());
    }
    return new BrowseResult(contentModel, count, count);
}
Also used : Item(org.fourthline.cling.support.model.item.Item) Container(org.fourthline.cling.support.model.container.Container) DIDLParser(org.fourthline.cling.support.contentdirectory.DIDLParser) ContentDirectoryException(org.fourthline.cling.support.contentdirectory.ContentDirectoryException) DIDLContent(org.fourthline.cling.support.model.DIDLContent) BrowseResult(org.fourthline.cling.support.model.BrowseResult) ContentDirectoryException(org.fourthline.cling.support.contentdirectory.ContentDirectoryException)

Example 4 with Item

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

Item (org.fourthline.cling.support.model.item.Item)4 Cursor (android.database.Cursor)2 ArrayList (java.util.ArrayList)2 Res (org.fourthline.cling.support.model.Res)2 Container (org.fourthline.cling.support.model.container.Container)2 Intent (android.content.Intent)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 PlaylistItem (com.kevinshen.beyondupnp.database.BeyondUpnpContract.PlaylistItem)1 ContentDirectoryException (org.fourthline.cling.support.contentdirectory.ContentDirectoryException)1 DIDLParser (org.fourthline.cling.support.contentdirectory.DIDLParser)1 BrowseResult (org.fourthline.cling.support.model.BrowseResult)1 DIDLContent (org.fourthline.cling.support.model.DIDLContent)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