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