本文整理汇总了Java中android.support.v4.media.MediaBrowserCompat类的典型用法代码示例。如果您正苦于以下问题:Java MediaBrowserCompat类的具体用法?Java MediaBrowserCompat怎么用?Java MediaBrowserCompat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaBrowserCompat类属于android.support.v4.media包,在下文中一共展示了MediaBrowserCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLoadChildren
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public void onLoadChildren(@NonNull final String parentId,
@NonNull final Result<List<MediaBrowserCompat.MediaItem>> result) {
Log.d(TAG, "====== on MusicService load children, parentId :" + parentId + " ====== ");
if (parentId.equals("")) {
result.sendResult(new ArrayList<MediaBrowserCompat.MediaItem>());
} else if (mProvider.isInitialize()) {
result.sendResult(mProvider.getChildren(parentId));
} else {
result.detach();
mProvider.setCallback(new MusicProvider.Callback() {
@Override
public void onMusicCatalogReady(boolean success) {
result.sendResult(mProvider.getChildren(parentId));
}
});
}
}
示例2: getView
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MediaBrowserCompat.MediaItem item = getItem(position);
int itemState = MediaItemViewHolder.STATE_NONE;
if (item.isPlayable()) {
String itemMediaId = item.getDescription().getMediaId();
int playbackState = PlaybackStateCompat.STATE_NONE;
if (mCurrentState != null) {
playbackState = mCurrentState.getState();
}
if (mCurrentMetadata != null
&& itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) {
if (playbackState == PlaybackStateCompat.STATE_PLAYING
|| playbackState == PlaybackStateCompat.STATE_BUFFERING) {
itemState = MediaItemViewHolder.STATE_PLAYING;
} else if (playbackState != PlaybackStateCompat.STATE_ERROR) {
itemState = MediaItemViewHolder.STATE_PAUSED;
}
}
}
return MediaItemViewHolder.setupView(
(Activity) getContext(), convertView, parent, item.getDescription(), itemState);
}
示例3: getView
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MediaBrowserCompat.MediaItem item = getItem(position);
int itemState = MediaItemViewHolder.STATE_NONE;
if (item.isPlayable()) {
String itemMediaId = item.getDescription().getMediaId();
int playbackState = PlaybackStateCompat.STATE_NONE;
if (mCurrentState != null) {
playbackState = mCurrentState.getState();
}
if (mCurrentMetadata != null
&& itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) {
if (playbackState == PlaybackState.STATE_PLAYING
|| playbackState == PlaybackState.STATE_BUFFERING) {
itemState = MediaItemViewHolder.STATE_PLAYING;
} else if (playbackState != PlaybackState.STATE_ERROR) {
itemState = MediaItemViewHolder.STATE_PAUSED;
}
}
}
return MediaItemViewHolder.setupView(
(Activity) getContext(), convertView, parent, item.getDescription(), itemState);
}
示例4: MediaInterface
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
public MediaInterface(FragmentActivity activity, MediaId mediaId, MediaInterfaceCallback callback) {
mFragmentActivity = activity;
mCallbacks = callback;
mPlayerControls = new MediaPlayerController(mediaId);
mPlayerControls.setMediaControls(mCallbacks, null);
mMediaBrowser = new MediaBrowserCompat(activity.getApplicationContext(),
new ComponentName(activity, MediaService.class),
new MediaBrowserCompat.ConnectionCallback() {
@Override
public void onConnected() {
MediaInterface.this.onConnected();
}
}, null);
mMediaBrowser.connect();
mSurfaceId = SURFACE_ID.incrementAndGet();
if (SURFACE_ID.longValue() == Long.MAX_VALUE)
SURFACE_ID.set(1);
}
示例5: isMediaItemPlaying
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
/**
* Determine if media item is playing (matches the currently playing media item).
*
* @param context for retrieving the {@link MediaControllerCompat}
* @param mediaItem to compare to currently playing {@link MediaBrowserCompat.MediaItem}
* @return boolean indicating whether media item matches currently playing media item
*/
public static boolean isMediaItemPlaying(Activity context, MediaBrowserCompat.MediaItem mediaItem) {
// Media item is considered to be playing or paused based on the controller's current
// media id
MediaControllerCompat controller = MediaControllerCompat.getMediaController(context);
if (controller != null && controller.getMetadata() != null) {
String currentPlayingMediaId = controller.getMetadata().getDescription()
.getMediaId();
String itemMusicId = MediaIDHelper.extractMusicIDFromMediaID(
mediaItem.getDescription().getMediaId());
if (currentPlayingMediaId != null
&& TextUtils.equals(currentPlayingMediaId, itemMusicId)) {
return true;
}
}
return false;
}
示例6: onBindViewHolder
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
MediaDescriptionCompat description;
final CardViewHolder cardViewHolder = (CardViewHolder) viewHolder;
// Determine description and playing state of item based on instance type
cardViewHolder.setState(MediaItemViewHolder.STATE_NONE);
if (item instanceof MediaBrowserCompat.MediaItem) {
MediaBrowserCompat.MediaItem mediaItem = (MediaBrowserCompat.MediaItem) item;
LogHelper.d(TAG, "onBindViewHolder MediaItem: ", mediaItem.toString());
description = mediaItem.getDescription();
cardViewHolder.setState(MediaItemViewHolder.getMediaItemState(mContext, mediaItem));
} else if (item instanceof MediaSessionCompat.QueueItem) {
MediaSessionCompat.QueueItem queueItem = (MediaSessionCompat.QueueItem) item;
LogHelper.d(TAG, "onBindViewHolder QueueItem: ", queueItem.toString());
description = queueItem.getDescription();
if (QueueHelper.isQueueItemPlaying(mContext, queueItem)) {
cardViewHolder.setState(MediaItemViewHolder.getStateFromController(mContext));
}
} else {
throw new IllegalArgumentException("Object must be MediaItem or QueueItem, not "
+ item.getClass().getSimpleName());
}
cardViewHolder.setupCardView(mContext, description);
}
示例7: setMediaId
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
protected void setMediaId(String mediaId) {
LogHelper.d(TAG, "setMediaId: ", mediaId);
if (TextUtils.equals(mMediaId, mediaId)) {
return;
}
MediaBrowserCompat mediaBrowser = mMediaFragmentListener.getMediaBrowser();
// First, unsubscribe from old mediaId:
if (mMediaId != null) {
mediaBrowser.unsubscribe(mMediaId);
}
if (mediaId == null) {
mediaId = mediaBrowser.getRoot();
}
mMediaId = mediaId;
mediaBrowser.subscribe(mMediaId, mSubscriptionCallback);
}
示例8: onItemClicked
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
if (controller == null) {
return;
}
MediaControllerCompat.TransportControls controls = controller.getTransportControls();
MediaBrowserCompat.MediaItem mediaItem = (MediaBrowserCompat.MediaItem) item;
if (!MediaIDHelper.isMediaItemPlaying(getActivity(), mediaItem)) {
controls.playFromMediaId(mediaItem.getMediaId(), null);
}
Intent intent = new Intent(getActivity(), TvPlaybackActivity.class);
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
getActivity(),
((ImageCardView) itemViewHolder.view).getMainImageView(),
TvVerticalGridActivity.SHARED_ELEMENT_NAME).toBundle();
getActivity().startActivity(intent, bundle);
}
示例9: onChildrenLoaded
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public void onChildrenLoaded(@NonNull String parentId,
@NonNull List<MediaBrowserCompat.MediaItem> children) {
try {
LogHelper.d(TAG, "fragment onChildrenLoaded, parentId=" + parentId +
" count=" + children.size());
checkForUserVisibleErrors(children.isEmpty());
mBrowserAdapter.clear();
for (MediaBrowserCompat.MediaItem item : children) {
mBrowserAdapter.add(item);
}
mBrowserAdapter.notifyDataSetChanged();
} catch (Throwable t) {
LogHelper.e(TAG, "Error on childrenloaded", t);
}
}
示例10: onStart
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public void onStart() {
super.onStart();
// fetch browsing information to fill the listview:
MediaBrowserCompat mediaBrowser = mMediaFragmentListener.getMediaBrowser();
LogHelper.d(TAG, "fragment.onStart, mediaId=", mMediaId,
" onConnected=" + mediaBrowser.isConnected());
if (mediaBrowser.isConnected()) {
onConnected();
}
// Registers BroadcastReceiver to track network connection changes.
this.getActivity().registerReceiver(mConnectivityChangeReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
示例11: onCreate
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogHelper.d(TAG, "Activity onCreate");
if (Build.VERSION.SDK_INT >= 21) {
// Since our app icon has the same color as colorPrimary, our entry in the Recent Apps
// list gets weird. We need to change either the icon or the color
// of the TaskDescription.
ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(
getTitle().toString(),
BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_white),
ResourceHelper.getThemeColor(this, R.attr.colorPrimary,
android.R.color.darker_gray));
setTaskDescription(taskDesc);
}
// Connect a media browser just to get the media session token. There are other ways
// this can be done, for example by sharing the session token directly.
mMediaBrowser = new MediaBrowserCompat(this,
new ComponentName(this, MusicService.class), mConnectionCallback, null);
}
示例12: onLoadChildren
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public void onLoadChildren(@NonNull final String parentMediaId, @NonNull final Result<List<MediaBrowserCompat.MediaItem>> result) {
LogHelper.v(LOG_TAG, "OnLoadChildren called.");
if (!mStationListProvider.isInitialized()) {
// use result.detach to allow calling result.sendResult from another thread:
result.detach();
mStationListProvider.retrieveMediaAsync(this, new StationListProvider.Callback() {
@Override
public void onStationListReady(boolean success) {
if (success) {
loadChildren(parentMediaId, result);
// } else {
// updatePlaybackState(getString(R.string.error_no_metadata));
// result.sendResult(Collections.<MediaBrowserCompat.MediaItem>emptyList());
}
}
});
} else {
// if our music catalog is already loaded/cached, load them into result immediately
loadChildren(parentMediaId, result);
}
}
示例13: loadChildren
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
private void loadChildren(@NonNull final String parentMediaId, final Result<List<MediaBrowserCompat.MediaItem>> result) {
List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
switch (parentMediaId) {
case MEDIA_ID_ROOT:
for (MediaMetadataCompat track : mStationListProvider.getAllMusics()) {
MediaBrowserCompat.MediaItem item =
new MediaBrowserCompat.MediaItem(track.getDescription(),
MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);
mediaItems.add(item);
}
break;
case MEDIA_ID_EMPTY_ROOT:
// since the client provided the empty root we'll just send back an empty list
break;
default:
LogHelper.w(LOG_TAG, "Skipping unmatched parentMediaId: " + parentMediaId);
break;
}
result.sendResult(mediaItems);
}
示例14: onLoadChildren
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
@Override
public void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
ChannelDatabase channelDatabase = ChannelDatabase.getInstance(getApplicationContext());
if (parentId.equals(MEDIA_ROOT_ID)) {
try {
for (Channel channel : channelDatabase.getChannels()) {
MediaDescriptionCompat descriptionCompat = new MediaDescriptionCompat.Builder()
.setMediaId(channel.getInternalProviderData().getVideoUrl())
.setTitle(channel.getDisplayName())
.setIconUri(Uri.parse(channel.getChannelLogo()))
.setSubtitle(getString(R.string.channel_no_xxx, channel.getDisplayNumber()))
.setDescription(channel.getDescription())
.setMediaUri(Uri.parse(channel.getInternalProviderData().getVideoUrl()))
.build();
mediaItems.add(new MediaBrowserCompat.MediaItem(descriptionCompat,
MediaBrowserCompat.MediaItem.FLAG_PLAYABLE));
}
result.sendResult(mediaItems);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
示例15: getMediaItems
import android.support.v4.media.MediaBrowserCompat; //导入依赖的package包/类
public static List<MediaBrowserCompat.MediaItem> getMediaItems() {
List<MediaBrowserCompat.MediaItem> result = new ArrayList<>();
for (MediaMetadataCompat metadata : music.values()) {
result.add(
new MediaBrowserCompat.MediaItem(
metadata.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE));
}
return result;
}