本文整理汇总了Java中org.fourthline.cling.support.model.item.Item.getFirstResource方法的典型用法代码示例。如果您正苦于以下问题:Java Item.getFirstResource方法的具体用法?Java Item.getFirstResource怎么用?Java Item.getFirstResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.fourthline.cling.support.model.item.Item
的用法示例。
在下文中一共展示了Item.getFirstResource方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playItems
import org.fourthline.cling.support.model.item.Item; //导入方法依赖的package包/类
@Override
public void playItems(List<Item> itemsToPlay) {
if (mListener == null)
return;
// Convert to MediaQueueItem for Cast.
List<MediaQueueItem> mediaItems = new ArrayList<>();
for (Item item : itemsToPlay) {
// Assumption: first non-null resource is the URL. No idea if correct.
Res urlResource = item.getFirstResource();
if (urlResource != null) {
MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
metadata.putString(MediaMetadata.KEY_TITLE, item.getTitle());
MediaInfo mediaInfo = new MediaInfo.Builder(urlResource.getValue())
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setContentType("audio/mp3")
.setMetadata(metadata)
.build();
mediaItems.add(new MediaQueueItem.Builder(mediaInfo).build());
}
}
mListener.playFiles(mediaItems);
}
示例2: startPhotoShow
import org.fourthline.cling.support.model.item.Item; //导入方法依赖的package包/类
protected void startPhotoShow(UpnpClient upnpClient,
Device<?, ?, ?> device, long durationInMillis, String instanceId) {
ContentDirectoryBrowseResult browseResult;
browseResult = upnpClient.browseSync(device, instanceId);
List<Item> items = browseResult.getResult().getItems();
for (Item item : items) {
Log.d(getClass().getName(), "ParentId: " + item.getParentID());
Log.d(getClass().getName(), "ItemId: " + item.getId());
Res resource = item.getFirstResource();
if (resource == null)
break;
Log.d(getClass().getName(), "ImportUri: " + resource.getImportUri());
Log.d(getClass().getName(),
"ProtocolInfo: " + resource.getProtocolInfo());
Log.d(getClass().getName(), "ContentFormat: "
+ resource.getProtocolInfo().getContentFormat());
Log.d(getClass().getName(), "Value: " + resource.getValue());
Log.d(getClass().getName(), "Picture: " + item.getTitle());
intentView(resource.getProtocolInfo().getContentFormat(),
Uri.parse(resource.getValue()), ImageViewerActivity.class);
myWait(durationInMillis); // Wait a bit between photo switch
}
}
示例3: playItem
import org.fourthline.cling.support.model.item.Item; //导入方法依赖的package包/类
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);
}
示例4: streamMp3
import org.fourthline.cling.support.model.item.Item; //导入方法依赖的package包/类
protected void streamMp3(String instanceId, String upnpServerid) {
UpnpClient upnpClient = new UpnpClient();
Device<?, ?, ?> device = lookupDevice(upnpClient, upnpServerid);
ContentDirectoryBrowseResult browseResult = null;
if (device != null) {
Log.d(getClass().getName(), "#####Device: " + device);
browseResult = upnpClient.browseSync(device, instanceId);
List<Item> items = browseResult.getResult().getItems();
for (Item item : items) {
Log.d(getClass().getName(), "ParentId: " + item.getParentID());
Log.d(getClass().getName(), "ItemId: " + item.getId());
Res resource = item.getFirstResource();
if (resource == null)
break;
Log.d(getClass().getName(),
"ImportUri: " + resource.getImportUri());
Log.d(getClass().getName(),
"Duration: " + resource.getDuration());
Log.d(getClass().getName(),
"ProtocolInfo: " + resource.getProtocolInfo());
Log.d(getClass().getName(), "ContentFormat: "
+ resource.getProtocolInfo().getContentFormat());
Log.d(getClass().getName(), "Value: " + resource.getValue());
intentView(resource.getProtocolInfo().getContentFormat(),
Uri.parse(resource.getValue()));
}
}
}
示例5: testInfoInstance
import org.fourthline.cling.support.model.item.Item; //导入方法依赖的package包/类
public void testInfoInstance() throws Exception {
UpnpClient upnpClient = new UpnpClient();
final List<Device<?, ?, ?>> devices = searchDevices(upnpClient);
ContentDirectoryBrowseResult browseResult = null;
for (Device<?, ?, ?> device : devices) {
Log.d(getClass().getName(),
"#####Device: " + device.getDisplayString());
browseResult = upnpClient.browseSync(device, "202");
List<Item> items = new ArrayList<Item>();
if( browseResult.getResult() != null) {
items = browseResult.getResult().getItems();
}
for (Item item : items) {
Log.d(getClass().getName(), "ParentId: " + item.getParentID());
Log.d(getClass().getName(), "ItemId: " + item.getId());
Res resource = item.getFirstResource();
if (resource == null)
break;
Log.d(getClass().getName(),
"ImportUri: " + resource.getImportUri());
Log.d(getClass().getName(),
"Duration: " + resource.getDuration());
Log.d(getClass().getName(),
"ProtocolInfo: " + resource.getProtocolInfo());
Log.d(getClass().getName(), "ContentFormat: "
+ resource.getProtocolInfo().getContentFormat());
Log.d(getClass().getName(), "Value: " + resource.getValue());
}
}
}
示例6: PlayableItem
import org.fourthline.cling.support.model.item.Item; //导入方法依赖的package包/类
@SuppressLint("SimpleDateFormat")
public PlayableItem(Item item, int defaultDuration){
this.item =item;
setTitle(item.getTitle());
Res resource = item.getFirstResource();
if (resource != null) {
setUri(Uri.parse(resource.getValue()));
String mimeType =resource.getProtocolInfo().getContentFormat();
if(mimeType == null || mimeType.equals("")){
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(getUri().toString());
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
}
setMimeType(mimeType);
// calculate duration
long millis = defaultDuration;
if (resource.getDuration() != null) {
try{
String[] tokens = resource.getDuration().split(":");
millis = (Long.valueOf(tokens[0]) * 3600 + Long.valueOf(tokens[1]) * 60 + Long.valueOf(tokens[2])) * 1000;
Log.d(getClass().getName(), "resource.getDuration(): " + resource.getDuration() +" millis: " + millis);
} catch (Exception e) {
Log.d(getClass().getName(), "bad duration format", e);
}
}
setDuration(millis);
}
}
示例7: startMusicPlay
import org.fourthline.cling.support.model.item.Item; //导入方法依赖的package包/类
protected void startMusicPlay(UpnpClient upnpClient,
Device<?, ?, ?> device, boolean background, String instanceId) {
ContentDirectoryBrowseResult browseResult;
browseResult = upnpClient.browseSync(device, instanceId);
List<Item> items = browseResult.getResult().getItems();
for (Item item : items) {
Log.d(getClass().getName(), "ParentId: " + item.getParentID());
Log.d(getClass().getName(), "ItemId: " + item.getId());
Res resource = item.getFirstResource();
if (resource == null)
break;
Log.d(getClass().getName(), "ImportUri: " + resource.getImportUri());
Log.d(getClass().getName(), "Duration: " + resource.getDuration());
Log.d(getClass().getName(),
"ProtocolInfo: " + resource.getProtocolInfo());
Log.d(getClass().getName(), "ContentFormat: "
+ resource.getProtocolInfo().getContentFormat());
Log.d(getClass().getName(), "Value: " + resource.getValue());
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
// just for a test
int millis = 0;
try {
Date date = dateFormat.parse(resource.getDuration());
millis = date.getHours() * 60 * 60 * 1000;
millis += date.getMinutes() * 60 * 1000;
millis += date.getSeconds() * 1000;
assertEquals(date.getTime(), millis);
Log.d(getClass().getName(),
"HappyHappy Joy Joy Duration in Millis=" + millis);
Log.d(getClass().getName(), "Playing: " + item.getTitle());
if (background) {
Log.d(getClass().getName(),
"Starting Background service... ");
Intent svc = new Intent(getContext(),
BackgroundMusicService.class);
svc.setData(Uri.parse(resource.getValue()));
getContext().startService(svc);
} else {
intentView(resource.getProtocolInfo().getContentFormat(),
Uri.parse(resource.getValue()));
}
} catch (ParseException e) {
Log.d(getClass().getName(), "bad duration format");
;
}
myWait(millis);
}
}