本文整理汇总了Java中android.support.v4.media.session.MediaSessionCompat.QueueItem方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSessionCompat.QueueItem方法的具体用法?Java MediaSessionCompat.QueueItem怎么用?Java MediaSessionCompat.QueueItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.media.session.MediaSessionCompat
的用法示例。
在下文中一共展示了MediaSessionCompat.QueueItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSkipToNext
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
@Override
public void onSkipToNext() {
// Update the media to skip to the next video.
Bundle bundle = new Bundle();
bundle.putBoolean(AUTO_PLAY, true);
int nextIndex = ++mQueueIndex;
if (nextIndex < mQueue.size()) {
MediaSessionCompat.QueueItem item = mQueue.get(nextIndex);
String mediaId = item.getDescription().getMediaId();
getActivity().getMediaController()
.getTransportControls()
.playFromMediaId(mediaId, bundle);
} else {
getActivity().onBackPressed(); // Return to details presenter.
}
}
示例2: onSkipToPrevious
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
@Override
public void onSkipToPrevious() {
// Update the media to skip to the previous video.
setPlaybackState(PlaybackState.STATE_SKIPPING_TO_PREVIOUS);
Bundle bundle = new Bundle();
bundle.putBoolean(AUTO_PLAY, true);
int prevIndex = --mQueueIndex;
if (prevIndex >= 0) {
MediaSessionCompat.QueueItem item = mQueue.get(prevIndex);
String mediaId = item.getDescription().getMediaId();
getActivity().getMediaController()
.getTransportControls()
.playFromMediaId(mediaId, bundle);
} else {
getActivity().onBackPressed(); // Return to details presenter.
}
}
示例3: getRandomQueue
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
/**
* Create a random queue.
*
* @param musicProvider the provider used for fetching music.
* @return list containing {@link MediaSessionCompat.QueueItem}'s
*/
public static List<MediaSessionCompat.QueueItem> getRandomQueue(MusicProvider musicProvider) {
List<MediaMetadataCompat> result = new ArrayList<>();
for (String genre : musicProvider.getGenres()) {
Iterable<MediaMetadataCompat> tracks = musicProvider.getMusicsByGenre(genre);
for (MediaMetadataCompat track : tracks) {
if (ThreadLocalRandom.current().nextBoolean()) {
result.add(track);
}
}
}
LogUtils.d(TAG, "getRandomQueue: result.size=", result.size());
Collections.shuffle(result);
return convertToQueue(result, MEDIA_ID_MUSICS_BY_SEARCH, "random");
}
示例4: updateNowPlayingList
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private void updateNowPlayingList(List<MediaSessionCompat.QueueItem> queue, long activeQueueId) {
if (mListRowAdapter != null) {
mListRowAdapter.clear();
if (activeQueueId != MediaSessionCompat.QueueItem.UNKNOWN_ID) {
Iterator<MediaSessionCompat.QueueItem> iterator = queue.iterator();
while (iterator.hasNext()) {
MediaSessionCompat.QueueItem queueItem = iterator.next();
if (activeQueueId != queueItem.getQueueId()) {
iterator.remove();
} else {
break;
}
}
}
mListRowAdapter.addAll(0, queue);
}
}
示例5: convertToQueue
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private static List<MediaSessionCompat.QueueItem> convertToQueue(
Iterable<MediaMetadataCompat> tracks, String... categories) {
List<MediaSessionCompat.QueueItem> queue = new ArrayList<>();
int count = 0;
for (MediaMetadataCompat track : tracks) {
// We create a hierarchy-aware mediaID, so we know what the queue is about by looking
// at the QueueItem media IDs.
String hierarchyAwareMediaID = MediaIDHelper.createMediaID(
track.getDescription().getMediaId(), categories);
MediaMetadataCompat trackCopy = new MediaMetadataCompat.Builder(track)
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID)
.build();
// We don't expect queues to change after created, so we use the item index as the
// queueId. Any other number unique in the queue would work.
MediaSessionCompat.QueueItem item = new MediaSessionCompat.QueueItem(trackCopy.getDescription(), count++);
queue.add(item);
}
return queue;
}
示例6: setCustomAction
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private void setCustomAction(PlaybackStateCompat.Builder stateBuilder) {
MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic();
if (currentMusic == null) {
return;
}
// Set appropriate "Favorite" icon on Custom action:
String mediaId = currentMusic.getDescription().getMediaId();
if (mediaId == null) {
return;
}
String musicId = MediaIDHelper.extractMusicIDFromMediaID(mediaId);
int favoriteIcon = mMusicProvider.isFavorite(musicId) ?
R.drawable.ic_star_on : R.drawable.ic_star_off;
LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ",
musicId, " current favorite=", mMusicProvider.isFavorite(musicId));
Bundle customActionExtras = new Bundle();
WearHelper.setShowCustomActionOnWear(customActionExtras, true);
stateBuilder.addCustomAction(new PlaybackStateCompat.CustomAction.Builder(
CUSTOM_ACTION_THUMBS_UP, mResources.getString(R.string.favorite), favoriteIcon)
.setExtras(customActionExtras)
.build());
}
示例7: onLoadFinished
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
if (cursor != null && cursor.moveToFirst()) {
switch (loader.getId()) {
case QUEUE_VIDEOS_LOADER: {
mQueue.clear();
while (!cursor.isAfterLast()) {
Video v = (Video) mVideoCursorMapper.convert(cursor);
// Set the queue index to the selected video.
if (v.id == mSelectedVideo.id) {
mQueueIndex = mQueue.size();
}
// Add the video to the queue.
MediaSessionCompat.QueueItem item = getQueueItem(v);
mQueue.add(item);
cursor.moveToNext();
}
mSession.setQueue(mQueue);
mSession.setQueueTitle(getString(R.string.queue_name));
break;
}
case RECOMMENDED_VIDEOS_LOADER: {
mVideoCursorAdapter.changeCursor(cursor);
break;
}
default: {
// Playing a specific video.
Video video = (Video) mVideoCursorMapper.convert(cursor);
playVideo(video, mAutoPlayExtras);
break;
}
}
}
}
示例8: getQueueItem
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private MediaSessionCompat.QueueItem getQueueItem(Video v) {
MediaDescriptionCompat desc = new MediaDescriptionCompat.Builder()
.setDescription(v.description)
.setMediaId(v.id + "")
.setIconUri(Uri.parse(v.cardImageUrl))
.setMediaUri(Uri.parse(v.videoUrl))
.setSubtitle(v.studio)
.setTitle(v.title)
.build();
return new MediaSessionCompat.QueueItem(desc, v.id);
}
示例9: updateMetadata
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private void updateMetadata() {
MediaSessionCompat.QueueItem queueItem = mQueueManager.getCurrentMedia();
String mediaId = queueItem.getDescription().getMediaId();
MediaMetadataCompat track = mProvider.getMusic(mediaId);
mSession.setMetadata(track);
//// TODO: 2017/10/19 load album art
postNotification();
}
示例10: setCurrentQueueItem
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public boolean setCurrentQueueItem(long queueId) {
int index = 0;
for (MediaSessionCompat.QueueItem item : mPlayingQueue) {
if (item.getQueueId() == queueId) {
setCurrentIndex(index);
return true;
}
index++;
}
return index >= 0;
}
示例11: setCurrentQueue
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public void setCurrentQueue(String title, List<MediaSessionCompat.QueueItem> newQueue,
String initialMediaId) {
mPlayingQueue = newQueue;
int index = 0;
if (initialMediaId != null) {
for (MediaSessionCompat.QueueItem item : mPlayingQueue) {
if (TextUtils.equals(initialMediaId, item.getDescription().getMediaId())) {
break;
}
index++;
}
}
mCurrentIndex = Math.max(index, 0);
mListener.onQueueUpdate(title, newQueue);
}
示例12: updateMetadata
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public void updateMetadata() {
MediaSessionCompat.QueueItem currentMedia = getCurrentMedia();
if (currentMedia == null) {
mListener.onMetadataRetrieveError("current media is null, can not update metadata");
return;
}
String mediaId = currentMedia.getDescription().getMediaId();
MediaMetadataCompat metadata = mProvider.getMusic(mediaId);
if (metadata == null) {
throw new RuntimeException("Invalid mediaId : " + mediaId);
}
mListener.onMetadataChanged(metadata);
//todo load album art and pass to provider for displaying to call mListener.onMetadataChanged again to update album art
}
示例13: handlePlayRequest
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public void handlePlayRequest() {
Log.i(TAG, "Handling play request. State = " + mPlayback.getState());
MediaSessionCompat.QueueItem mCurrentMedia = mQueueManager.getCurrentMedia();
if (mCurrentMedia == null) {
return; // Nothing to play
}
mServiceCallback.onPlaybackStart();
mPlayback.play(mCurrentMedia);
}
示例14: setIcon
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public void setIcon(Bitmap bitmap) {
MediaDescriptionCompat desc = mQueueItem.getDescription();
desc = new MediaDescriptionCompat.Builder()
.setTitle(desc.getTitle())
.setDescription(desc.getDescription())
.setMediaId(desc.getMediaId())
.setMediaUri(desc.getMediaUri())
.setIconUri(desc.getIconUri())
.setIconBitmap(bitmap)
.setExtras(desc.getExtras())
.setSubtitle(desc.getSubtitle())
.build();
mQueueItem = new MediaSessionCompat.QueueItem(desc, mQueueItem.getQueueId());
}
示例15: handlePlayRequest
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
/**
* Handle a request to play music
*/
public void handlePlayRequest() {
LogHelper.d(TAG, "handlePlayRequest: mState=" + mPlayback.getState());
MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic();
if (currentMusic != null) {
mServiceCallback.onPlaybackStart();
mPlayback.play(currentMusic);
}
}