当前位置: 首页>>代码示例>>Java>>正文


Java MediaBrowserCompat.MediaItem方法代码示例

本文整理汇总了Java中android.support.v4.media.MediaBrowserCompat.MediaItem方法的典型用法代码示例。如果您正苦于以下问题:Java MediaBrowserCompat.MediaItem方法的具体用法?Java MediaBrowserCompat.MediaItem怎么用?Java MediaBrowserCompat.MediaItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.media.MediaBrowserCompat的用法示例。


在下文中一共展示了MediaBrowserCompat.MediaItem方法的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));
            }
        });
    }
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:20,代码来源:MusicService.java

示例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 == 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);
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:24,代码来源:MusicPlayerActivity.java

示例3: 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;
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:24,代码来源:MediaIDHelper.java

示例4: 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);
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:27,代码来源:CardPresenter.java

示例5: 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);
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:24,代码来源:TvVerticalGridFragment.java

示例6: 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);
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:17,代码来源:MediaBrowserFragment.java

示例7: 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);
        }

    }
 
开发者ID:y20k,项目名称:transistor,代码行数:27,代码来源:PlayerService.java

示例8: 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);
}
 
开发者ID:y20k,项目名称:transistor,代码行数:22,代码来源:PlayerService.java

示例9: 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();
        }
    }
}
 
开发者ID:Fleker,项目名称:CumulusTV,代码行数:25,代码来源:CumulusBrowseService.java

示例10: 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;
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:10,代码来源:MusicLibrary.java

示例11: onMediaItemSelected

import android.support.v4.media.MediaBrowserCompat; //导入方法依赖的package包/类
private void onMediaItemSelected(MediaBrowserCompat.MediaItem item) {
    if (item.isPlayable()) {
        // TODO: [2] Remove the following lines for playback in a Service
        MediaMetadataCompat metadata = MusicLibrary.getMetadata(this, item.getMediaId());
        mPlaybackManager.play(metadata);
        updateMetadata(metadata);

        // TODO: [2] Uncomment the following block for playback in a Service
        /*
        MediaControllerCompat.getMediaController(this)
                .getTransportControls()
                .playFromMediaId(item.getMediaId(), null);
        */
    }
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:16,代码来源:MusicPlayerActivity.java

示例12: getMediaItems

import android.support.v4.media.MediaBrowserCompat; //导入方法依赖的package包/类
public static List<MediaBrowserCompat.MediaItem> getMediaItems() {
    if (result.size() > 0) {
        return result;
    }
    for (MediaMetadataCompat metadata : music.values()) {
        result.add(
                new MediaBrowserCompat.MediaItem(
                        metadata.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE));
    }
    return result;
}
 
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:12,代码来源:LocalMusicLibrary.java

示例13: bindData

import android.support.v4.media.MediaBrowserCompat; //导入方法依赖的package包/类
@Override
protected void bindData(ViewHolder holder, MediaBrowserCompat.MediaItem mediaItem) {
    Log.d(TAG, "bindData() called with: holder = [" + holder + "], mediaItem = [" + mediaItem
            + "]");
    MediaDescriptionCompat description = mediaItem.getDescription();
    Log.d(TAG, "bindData: description: " + description.toString());
    holder.setText(R.id.media_item_name, description.getTitle());
    Bitmap iconBitmap = description.getIconBitmap();
    Log.d(TAG, "iconBitmap: " + iconBitmap);
    holder.setImageBitmap(R.id.media_item_pic, iconBitmap);
}
 
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:12,代码来源:MediaItemAdapter.java

示例14: onChildrenLoaded

import android.support.v4.media.MediaBrowserCompat; //导入方法依赖的package包/类
@Override
public void onChildrenLoaded(@NonNull String parentId,
                             @NonNull List<MediaBrowserCompat.MediaItem> children) {
    assert mMediaController != null;

    // Queue up all media items for this simple sample.
    for (final MediaBrowserCompat.MediaItem mediaItem : children) {
        mMediaController.addQueueItem(mediaItem.getDescription());
    }

    // Call "playFromMedia" so the UI is updated.
    mMediaController.getTransportControls().prepare();
}
 
开发者ID:nazmulidris,项目名称:mediasession-mediaplayer,代码行数:14,代码来源:MediaBrowserAdapter.java

示例15: getChildren

import android.support.v4.media.MediaBrowserCompat; //导入方法依赖的package包/类
public static List<MediaBrowserCompat.MediaItem> getChildren(String mediaId, Resources resources){
    List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
    if (!isBrowseable(mediaId)) {
        return mediaItems;
    }
    if (MEDIA_ID_ROOT.equals(mediaId)) {
        mediaItems.add(createBrowseableMediaItemForRoot(resources));
    }
    return mediaItems;
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:11,代码来源:MediaHelper.java


注:本文中的android.support.v4.media.MediaBrowserCompat.MediaItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。