z-huang / InnerTune

A Material 3 YouTube Music client for Android
GNU General Public License v3.0
4.13k stars 258 forks source link

Search issue on Android Auto #1412

Open scanetuk opened 4 weeks ago

scanetuk commented 4 weeks ago

Checklist

Steps to reproduce the bug

Fantastic app, bug found tried to search in Android Auto

Expected behavior

Search results should appear

Actual behavior

Goes quickley flashes to home screen then to a blank screen as screenshot

Screenshots/Screen recordings

image moves to this screen when clicking the magnifying glass image

Logs

Looks like it may be because "override fun onSearch" and "override fun onGetSearchResult" are missing from MediaLibrarySessionCallback.kt as hits them when I add them in and do a search in Android Auto, however just learning Java/Kotlin so not sure as yet how to do the search and retreval of search results.

InnerTune version

0.5.7

Android version

Android 13

Additional information

No response

scanetuk commented 3 weeks ago

Here is a start on the Android auto search, pop this into MediaLibrarySessionCallback.kt and it will search your song list:

override fun onSearch(
    session: MediaLibrarySession,
    browser: MediaSession.ControllerInfo,
    query: String,
    params: LibraryParams?,
): ListenableFuture<LibraryResult<Void>> {
    session.notifySearchResultChanged(
        browser,
        query,
        1,
        params
    )
    return Futures.immediateFuture(LibraryResult.ofVoid(params))
}
override fun onGetSearchResult(
    session: MediaLibrarySession,
    browser: MediaSession.ControllerInfo,
    query: String,
    page: Int,
    pageSize: Int,
    params: LibraryParams?,
): ListenableFuture<LibraryResult<ImmutableList<MediaItem>>>  = scope.future(Dispatchers.IO) {
    var parentId = "song"
    LibraryResult.ofItemList(
        when (parentId) {
            MusicService.SONG -> database.searchSongs(query, 5).first().map { it.toMediaItem("song") }
            else -> when {
                else -> emptyList()
            }
        },
        params
    )
}
z-huang commented 3 weeks ago

@scanetuk Thanks! Do you expect to search from local database or online?

scanetuk commented 3 weeks ago

Maybe to start when searching check local database first to see if the artist/album/song a is downloaded to save on bandwidth and then gets a list of results from online?

scanetuk commented 3 weeks ago

@z-huang - I have got the search for any local database song working in Android Auto plus got the Google Search Assistant voice control working to search for any local database song and "next", "stop", "start" etc voice controls working, not sure how the Github works, can you tell me the best way to give you the code? cheers

z-huang commented 3 weeks ago

Great! Please make a pull request.