本文整理汇总了Java中android.media.session.MediaSession.QueueItem方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSession.QueueItem方法的具体用法?Java MediaSession.QueueItem怎么用?Java MediaSession.QueueItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.MediaSession
的用法示例。
在下文中一共展示了MediaSession.QueueItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToQueue
import android.media.session.MediaSession; //导入方法依赖的package包/类
private static List<MediaSession.QueueItem> convertToQueue(
Iterable<MediaMetadata> tracks, String... categories) {
List<MediaSession.QueueItem> queue = new ArrayList<>();
int count = 0;
for (MediaMetadata 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);
MediaMetadata trackCopy = new MediaMetadata.Builder(track)
.putString(MediaMetadata.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.
MediaSession.QueueItem item = new MediaSession.QueueItem(
trackCopy.getDescription(), count++);
queue.add(item);
}
return queue;
}
示例2: getRandomQueue
import android.media.session.MediaSession; //导入方法依赖的package包/类
/**
* Create a random queue.
*
* @param musicProvider the provider used for fetching music.
* @return list containing {@link MediaSession.QueueItem}'s
*/
public static List<MediaSession.QueueItem> getRandomQueue(MusicProvider musicProvider) {
List<MediaMetadata> result = new ArrayList<>();
for (String genre: musicProvider.getGenres()) {
Iterable<MediaMetadata> tracks = musicProvider.getMusicsByGenre(genre);
for (MediaMetadata track: tracks) {
if (ThreadLocalRandom.current().nextBoolean()) {
result.add(track);
}
}
}
LogHelper.d(TAG, "getRandomQueue: result.size=", result.size());
Collections.shuffle(result);
return convertToQueue(result, MEDIA_ID_MUSICS_BY_SEARCH, "random");
}
示例3: equalsQueue
import android.media.session.MediaSession; //导入方法依赖的package包/类
private boolean equalsQueue(List<MediaSession.QueueItem> list1,
List<MediaSession.QueueItem> list2) {
if (list1 == list2) {
return true;
}
if (list1 == null || list2 == null) {
return false;
}
if (list1.size() != list2.size()) {
return false;
}
for (int i=0; i<list1.size(); i++) {
if (list1.get(i).getQueueId() != list2.get(i).getQueueId()) {
return false;
}
if (!TextUtils.equals(list1.get(i).getDescription().getMediaId(),
list2.get(i).getDescription().getMediaId())) {
return false;
}
}
return true;
}
示例4: updatePlaylist
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void updatePlaylist(List<DownloadFile> playlist) {
List<MediaSession.QueueItem> queue = new ArrayList<>();
for(DownloadFile file: playlist) {
Entry entry = file.getSong();
MediaDescription description = new MediaDescription.Builder()
.setMediaId(entry.getId())
.setTitle(entry.getTitle())
.setSubtitle(entry.getAlbumDisplay())
.build();
MediaSession.QueueItem item = new MediaSession.QueueItem(description, entry.getId().hashCode());
queue.add(item);
}
mediaSession.setQueue(queue);
currentQueue = playlist;
}
示例5: buildQueueList
import android.media.session.MediaSession; //导入方法依赖的package包/类
@DebugLog @TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static List<MediaSession.QueueItem> buildQueueList(Context context, long[] songs) {
List<MediaSession.QueueItem> list = new ArrayList<>(15);
if (songs.length == 0) return list;
final OrderPreservingCursor c = new OrderPreservingCursor(context, songs,
MusicProvider.RECENTS_URI, Projections.RECENT_SONGS, "", null);
c.moveToFirst();
int ii=0;
do {
list.add(new MediaSession.QueueItem(
new MediaDescription.Builder()
.setTitle(c.getString(c.getColumnIndex(MusicStore.Cols.NAME)))
.setSubtitle(c.getString(c.getColumnIndex(MusicStore.Cols.ARTIST_NAME)))
.setMediaId(c.getString(c.getColumnIndex(MusicStore.Cols.IDENTITY)))
.build(),
songs[ii]
));
} while (c.moveToNext() && ++ii<15);
c.close();
return list;
}
示例6: onPlayFromMediaId
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onPlayFromMediaId(String mediaId, Bundle extras) {
String args[] = mediaId.split("_");
if (args.length != 2) {
return;
}
try {
int did = Integer.parseInt(args[0]);
int id = Integer.parseInt(args[1]);
ArrayList<MessageObject> arrayList = musicObjects.get(did);
ArrayList<MediaSession.QueueItem> arrayList1 = musicQueues.get(did);
if (arrayList == null || id < 0 || id >= arrayList.size()) {
return;
}
lastSelectedDialog = did;
ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE).edit().putInt("auto_lastSelectedDialog", did).commit();
MediaController.getInstance().setPlaylist(arrayList, arrayList.get(id), false);
mediaSession.setQueue(arrayList1);
if (did > 0) {
TLRPC.User user = users.get(did);
if (user != null) {
mediaSession.setQueueTitle(ContactsController.formatName(user.first_name, user.last_name));
} else {
mediaSession.setQueueTitle("DELETED USER");
}
} else {
TLRPC.Chat chat = chats.get(-did);
if (chat != null) {
mediaSession.setQueueTitle(chat.title);
} else {
mediaSession.setQueueTitle("DELETED CHAT");
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
handlePlayRequest();
}
示例7: updatePlaybackState
import android.media.session.MediaSession; //导入方法依赖的package包/类
/**
* Update the current media player state, optionally showing an error message.
*
* @param error if not null, error message to present to the user.
*/
private void updatePlaybackState(String error) {
LogHelper.d(TAG, "updatePlaybackState, playback state=" + mPlayback.getState());
long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
if (mPlayback != null && mPlayback.isConnected()) {
position = mPlayback.getCurrentStreamPosition();
}
PlaybackState.Builder stateBuilder = new PlaybackState.Builder()
.setActions(getAvailableActions());
setCustomAction(stateBuilder);
int state = mPlayback.getState();
// If there is an error message, send it to the playback state:
if (error != null) {
// Error states are really only supposed to be used for errors that cause playback to
// stop unexpectedly and persist until the user takes action to fix it.
stateBuilder.setErrorMessage(error);
state = PlaybackState.STATE_ERROR;
}
stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
// Set the activeQueueItemId if the current index is valid.
if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) {
MediaSession.QueueItem item = mPlayingQueue.get(mCurrentIndexOnQueue);
stateBuilder.setActiveQueueItemId(item.getQueueId());
}
mSession.setPlaybackState(stateBuilder.build());
if (state == PlaybackState.STATE_PLAYING || state == PlaybackState.STATE_PAUSED) {
mMediaNotificationManager.startNotification();
}
}
示例8: getCurrentPlayingMusic
import android.media.session.MediaSession; //导入方法依赖的package包/类
private MediaMetadata getCurrentPlayingMusic() {
if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) {
MediaSession.QueueItem item = mPlayingQueue.get(mCurrentIndexOnQueue);
if (item != null) {
LogHelper.d(TAG, "getCurrentPlayingMusic for musicId=",
item.getDescription().getMediaId());
return mMusicProvider.getMusic(
MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));
}
}
return null;
}
示例9: onMetadataChanged
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onMetadataChanged(String mediaId) {
LogHelper.d(TAG, "onMetadataChanged", mediaId);
List<MediaSession.QueueItem> queue = QueueHelper.getPlayingQueue(mediaId, mMusicProvider);
int index = QueueHelper.getMusicIndexOnQueue(queue, mediaId);
if (index > -1) {
mCurrentIndexOnQueue = index;
mPlayingQueue = queue;
updateMetadata();
}
}
示例10: getPlayingQueue
import android.media.session.MediaSession; //导入方法依赖的package包/类
public static List<MediaSession.QueueItem> getPlayingQueue(String mediaId,
MusicProvider musicProvider) {
// extract the browsing hierarchy from the media ID:
String[] hierarchy = MediaIDHelper.getHierarchy(mediaId);
if (hierarchy.length != 2) {
LogHelper.e(TAG, "Could not build a playing queue for this mediaId: ", mediaId);
return null;
}
String categoryType = hierarchy[0];
String categoryValue = hierarchy[1];
LogHelper.d(TAG, "Creating playing queue for ", categoryType, ", ", categoryValue);
Iterable<MediaMetadata> tracks = null;
// This sample only supports genre and by_search category types.
if (categoryType.equals(MEDIA_ID_MUSICS_BY_GENRE)) {
tracks = musicProvider.getMusicsByGenre(categoryValue);
} else if (categoryType.equals(MEDIA_ID_MUSICS_BY_SEARCH)) {
tracks = musicProvider.searchMusicBySongTitle(categoryValue);
}
if (tracks == null) {
LogHelper.e(TAG, "Unrecognized category type: ", categoryType, " for media ", mediaId);
return null;
}
return convertToQueue(tracks, hierarchy[0], hierarchy[1]);
}
示例11: getPlayingQueueFromSearch
import android.media.session.MediaSession; //导入方法依赖的package包/类
public static List<MediaSession.QueueItem> getPlayingQueueFromSearch(String query,
Bundle queryParams, MusicProvider musicProvider) {
LogHelper.d(TAG, "Creating playing queue for musics from search: ", query,
" params=", queryParams);
VoiceSearchParams params = new VoiceSearchParams(query, queryParams);
LogHelper.d(TAG, "VoiceSearchParams: ", params);
if (params.isAny) {
// If isAny is true, we will play anything. This is app-dependent, and can be,
// for example, favorite playlists, "I'm feeling lucky", most recent, etc.
return getRandomQueue(musicProvider);
}
Iterable<MediaMetadata> result = null;
if (params.isAlbumFocus) {
result = musicProvider.searchMusicByAlbum(params.album);
} else if (params.isGenreFocus) {
result = musicProvider.getMusicsByGenre(params.genre);
} else if (params.isArtistFocus) {
result = musicProvider.searchMusicByArtist(params.artist);
} else if (params.isSongFocus) {
result = musicProvider.searchMusicBySongTitle(params.song);
}
// If there was no results using media focus parameter, we do an unstructured query.
// This is useful when the user is searching for something that looks like an artist
// to Google, for example, but is not. For example, a user searching for Madonna on
// a PodCast application wouldn't get results if we only looked at the
// Artist (podcast author). Then, we can instead do an unstructured search.
if (params.isUnstructured || result == null || !result.iterator().hasNext()) {
// To keep it simple for this example, we do unstructured searches on the
// song title only. A real world application could search on other fields as well.
result = musicProvider.searchMusicBySongTitle(query);
}
return convertToQueue(result, MEDIA_ID_MUSICS_BY_SEARCH, query);
}
示例12: getMusicIndexOnQueue
import android.media.session.MediaSession; //导入方法依赖的package包/类
public static int getMusicIndexOnQueue(Iterable<MediaSession.QueueItem> queue,
String mediaId) {
int index = 0;
for (MediaSession.QueueItem item : queue) {
if (mediaId.equals(item.getDescription().getMediaId())) {
return index;
}
index++;
}
return -1;
}
示例13: onItemClicked
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
if (item instanceof MediaSession.QueueItem) {
LogHelper.d(TAG, "item: ", item.toString());
getActivity().getMediaController().getTransportControls()
.skipToQueueItem(((MediaSession.QueueItem) item).getQueueId());
}
}
示例14: getRandomQueue
import android.media.session.MediaSession; //导入方法依赖的package包/类
/**
* Create a random queue. For simplicity sake, instead of a random queue, we create a
* queue using the first genre.
*
* @param musicProvider the provider used for fetching music.
* @return list containing {@link MediaSession.QueueItem}'s
*/
public static List<MediaSession.QueueItem> getRandomQueue(MusicProvider musicProvider) {
Iterator<String> genres = musicProvider.getGenres().iterator();
if (!genres.hasNext()) {
return Collections.emptyList();
}
String genre = genres.next();
Iterable<MediaMetadata> tracks = musicProvider.getMusicsByGenre(genre);
return convertToQueue(tracks, MEDIA_ID_MUSICS_BY_GENRE, genre);
}
示例15: getQueue
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public List<MediaSessionCompat.QueueItem> getQueue() {
List<MediaSession.QueueItem> queue = mController.getQueue();
if (queue == null || queue.isEmpty()) {
return null;
}
List<MediaSessionCompat.QueueItem> list = new ArrayList<>(queue.size());
for (MediaSession.QueueItem item : queue) {
MediaSessionCompat.QueueItem qi = MediaSessionCompat.QueueItem.obtain(item);
list.add(qi);
}
return list;
}