Search in sources :

Example 1 with TrackAlbumFetchError

use of org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError in project malp by gateship-one.

the class ArtworkManager method fetchAlbumImage.

/**
 * Starts an asynchronous fetch for the image of the given album
 *
 * @param track Track to be used for image fetching
 */
public void fetchAlbumImage(final MPDTrack track) {
    // Create a dummy album
    MPDAlbum album = new MPDAlbum(track.getTrackAlbum());
    album.setMBID(track.getTrackAlbumMBID());
    album.setArtistName(track.getTrackAlbumArtist());
    // Check if user-specified HTTP cover download is activated
    if (HTTPAlbumImageProvider.getInstance(mContext).getActive()) {
        HTTPAlbumImageProvider.getInstance(mContext).fetchAlbumImage(track, response -> new InsertTrackAlbumImageTask().execute(response), new TrackAlbumFetchError() {

            @Override
            public void fetchJSONException(MPDTrack track, JSONException exception) {
            }

            @Override
            public void fetchVolleyError(MPDTrack track, VolleyError error) {
                Log.v(TAG, "Local HTTP download failed, try user-selected download provider");
                MPDAlbum album = new MPDAlbum(track.getTrackAlbum());
                album.setMBID(track.getTrackAlbumMBID());
                album.setArtistName(track.getTrackAlbumArtist());
                fetchAlbumImage(album);
                synchronized (mTrackList) {
                    if (!mTrackList.isEmpty()) {
                        fetchNextBulkTrackAlbum();
                    }
                }
            }
        });
    } else {
        // Use the dummy album to fetch the image
        fetchAlbumImage(album);
    }
}
Also used : VolleyError(com.android.volley.VolleyError) MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum) JSONException(org.json.JSONException) TrackAlbumFetchError(org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError)

Aggregations

VolleyError (com.android.volley.VolleyError)1 TrackAlbumFetchError (org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError)1 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)1 MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)1 JSONException (org.json.JSONException)1