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();
}
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;
}
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);
}
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;
}
Aggregations