Search in sources :

Example 1 with SearchResult

use of se.michaelthelin.spotify.model_objects.special.SearchResult in project spotify-web-api-java by spotify-web-api-java.

the class SearchItemExample method searchItem_Sync.

public static void searchItem_Sync() {
    try {
        final SearchResult searchResult = searchItemRequest.execute();
        System.out.println("Total tracks: " + searchResult.getTracks().getTotal());
    } catch (IOException | SpotifyWebApiException | ParseException e) {
        System.out.println("Error: " + e.getMessage());
    }
}
Also used : SearchResult(se.michaelthelin.spotify.model_objects.special.SearchResult) IOException(java.io.IOException) ParseException(org.apache.hc.core5.http.ParseException) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException)

Example 2 with SearchResult

use of se.michaelthelin.spotify.model_objects.special.SearchResult in project spotify-web-api-java by spotify-web-api-java.

the class SearchItemExample method searchItem_Async.

public static void searchItem_Async() {
    try {
        final CompletableFuture<SearchResult> searchResultFuture = searchItemRequest.executeAsync();
        // Thread free to do other tasks...
        // Example Only. Never block in production code.
        final SearchResult searchResult = searchResultFuture.join();
        System.out.println("Total tracks: " + searchResult.getTracks().getTotal());
    } catch (CompletionException e) {
        System.out.println("Error: " + e.getCause().getMessage());
    } catch (CancellationException e) {
        System.out.println("Async operation cancelled.");
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) SearchResult(se.michaelthelin.spotify.model_objects.special.SearchResult)

Aggregations

SearchResult (se.michaelthelin.spotify.model_objects.special.SearchResult)2 IOException (java.io.IOException)1 CancellationException (java.util.concurrent.CancellationException)1 CompletionException (java.util.concurrent.CompletionException)1 ParseException (org.apache.hc.core5.http.ParseException)1 SpotifyWebApiException (se.michaelthelin.spotify.exceptions.SpotifyWebApiException)1