當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaSession.QueueItem方法代碼示例

本文整理匯總了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;

}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:25,代碼來源:QueueHelper.java

示例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");
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:24,代碼來源:QueueHelper.java

示例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;
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:23,代碼來源:TvPlaybackFragment.java

示例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;
}
 
開發者ID:popeen,項目名稱:Popeens-DSub,代碼行數:20,代碼來源:RemoteControlClientLP.java

示例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;
}
 
開發者ID:OpenSilk,項目名稱:Orpheus,代碼行數:22,代碼來源:MusicProviderUtil.java

示例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();
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:39,代碼來源:MusicBrowserService.java

示例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();
    }
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:40,代碼來源:MusicService.java

示例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;
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:13,代碼來源:MusicService.java

示例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();
    }
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:12,代碼來源:MusicService.java

示例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]);
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:31,代碼來源:QueueHelper.java

示例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);
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:41,代碼來源:QueueHelper.java

示例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;
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:12,代碼來源:QueueHelper.java

示例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());
    }
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:11,代碼來源:TvPlaybackFragment.java

示例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);
}
 
開發者ID:ErNaveen,項目名稱:UniversalMusicPlayer,代碼行數:18,代碼來源:QueueHelper.java

示例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;
}
 
開發者ID:OpenSilk,項目名稱:Orpheus,代碼行數:14,代碼來源:MediaControllerProxyImplL.java


注:本文中的android.media.session.MediaSession.QueueItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。