Search in sources :

Example 1 with VoiceSearchParams

use of com.example.android.uamp.VoiceSearchParams in project android-UniversalMusicPlayer by googlesamples.

the class QueueHelper method getPlayingQueueFromSearch.

public static List<MediaSessionCompat.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) {
        // for example, favorite playlists, "I'm feeling lucky", most recent, etc.
        return getRandomQueue(musicProvider);
    }
    List<MediaMetadataCompat> 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);
    }
    // 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 and genre only. A real world application could search
        // on other fields as well.
        result = musicProvider.searchMusicBySongTitle(query);
        if (result.isEmpty()) {
            result = musicProvider.searchMusicByGenre(query);
        }
    }
    return convertToQueue(result, MEDIA_ID_MUSICS_BY_SEARCH, query);
}
Also used : VoiceSearchParams(com.example.android.uamp.VoiceSearchParams) MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat)

Aggregations

MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)1 VoiceSearchParams (com.example.android.uamp.VoiceSearchParams)1