本文整理汇总了Java中android.support.v7.media.MediaControlIntent.ACTION_PLAY属性的典型用法代码示例。如果您正苦于以下问题:Java MediaControlIntent.ACTION_PLAY属性的具体用法?Java MediaControlIntent.ACTION_PLAY怎么用?Java MediaControlIntent.ACTION_PLAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.support.v7.media.MediaControlIntent
的用法示例。
在下文中一共展示了MediaControlIntent.ACTION_PLAY属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: play
/**
* Sets current track in renderer to specified item in playlist, then
* starts playback.
*/
public void play(int trackNumber) {
if (trackNumber < 0 || trackNumber >= mPlaylist.size())
return;
mCurrentTrack = trackNumber;
Item track = mPlaylist.get(trackNumber);
DIDLParser parser = new DIDLParser();
DIDLContent didl = new DIDLContent();
didl.addItem(track);
String metadata = "";
try {
metadata = parser.generate(didl, true);
}
catch (Exception e) {
Log.w(TAG, "Metadata generation failed", e);
}
Intent intent = new Intent(MediaControlIntent.ACTION_PLAY);
intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
intent.setData(Uri.parse(track.getFirstResource().getValue()));
intent.putExtra(MediaControlIntent.EXTRA_ITEM_METADATA, metadata);
mMediaRouter.getSelectedRoute().sendControlRequest(intent,
new ControlRequestCallback() {
@Override
public void onResult(Bundle data) {
mSessionId = data.getString(MediaControlIntent.EXTRA_SESSION_ID);
mItemId = data.getString(MediaControlIntent.EXTRA_ITEM_ID);
mPollingStatus = true;
new CreateNotificationTask().execute(mPlaylist.get(mCurrentTrack)
.getFirstPropertyValue(DIDLObject.Property.UPNP.ALBUM_ART_URI.class));
if (mRouterFragment.get() != null) {
mRouterFragment.get().scrollToCurrent();
}
}
});
}
示例2: makePlayIntent
private Intent makePlayIntent(MediaItem item) {
Intent intent = new Intent(MediaControlIntent.ACTION_PLAY);
intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
intent.setDataAndType(item.mUri, "video/mp4");
return intent;
}
示例3: onPlayMedia
@Override
protected void onPlayMedia(final MediaInfo media) {
if (media == null) {
return;
}
MediaMetadata metadata = media.getMetadata();
Log.d(TAG, "Casting " + metadata.getString(MediaMetadata.KEY_TITLE) + " ("
+ media.getContentType() + ")");
Intent intent = new Intent(MediaControlIntent.ACTION_PLAY);
intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
intent.setDataAndType(Uri.parse(media.getContentId()), media.getContentType());
intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, mSessionId);
intent.putExtra(MediaControlIntent.EXTRA_ITEM_STATUS_UPDATE_RECEIVER,
mMediaStatusUpdateIntent);
Bundle metadataBundle = new Bundle();
String title = metadata.getString(MediaMetadata.KEY_TITLE);
if (!TextUtils.isEmpty(title)) {
metadataBundle.putString(MediaItemMetadata.KEY_TITLE, title);
}
List<WebImage> images = metadata.getImages();
String artist = metadata.getString(MediaMetadata.KEY_ARTIST);
if (artist == null) {
artist = metadata.getString(MediaMetadata.KEY_STUDIO);
}
if (!TextUtils.isEmpty(artist)) {
metadataBundle.putString(MediaItemMetadata.KEY_ARTIST, artist);
}
if ((images != null) && !images.isEmpty()) {
Uri imageUrl = images.get(0).getUrl();
if (imageUrl != null) {
metadataBundle.putString(MediaItemMetadata.KEY_ARTWORK_URI, imageUrl.toString());
}
}
intent.putExtra(MediaControlIntent.EXTRA_ITEM_METADATA, metadataBundle);
sendIntentToRoute(intent, mMediaResultHandler);
}