Sunday, 2 December 2018

MediaBrowserCompat queue find item

As per Uamp sample when onPlayFromMediaId is called its mediaId is matched with list of queueitems already stored using iterator as below

public static int getMusicIndexOnQueue(Iterable<MediaSessionCompat.QueueItem> queue,
         String mediaId) {
    int index = 0;
    for (MediaSessionCompat.QueueItem item : queue) {
        if (mediaId.equals(item.getDescription().getMediaId())) {
            return index;
        }
        index++;
    }
    return -1;
} 

this works great unless you have some thousand items in your list, its lags badly, is there any way I can get the index on queue in this scenario?

P.S.- This code is from v1 branch although v2 kotlin based branch has the same concept.



from MediaBrowserCompat queue find item

No comments:

Post a Comment