Search in sources :

Example 1 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.

the class FanartActivity method onDisconnected.

@Override
protected void onDisconnected() {
    updateMPDStatus(new MPDCurrentStatus());
    updateMPDCurrentTrack(new MPDTrack(""));
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) MPDCurrentStatus(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus)

Example 2 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.

the class FanartActivity method syncFanart.

/**
 * Checks if new fanart is available for the given artist. This ensures that the user
 * gets new images from time to time if they have old images in cache.
 *
 * @param track Track to check for new fanart for.
 */
private void syncFanart(final MPDTrack track) {
    // Get a list of fanart urls for the current artist
    if (!downloadAllowed()) {
        return;
    }
    FanartTVManager.getInstance(getApplicationContext()).getArtistFanartURLs(track.getTrackArtistMBID(), response -> {
        for (final String url : response) {
            // Check if the given image is in the cache already.
            if (mFanartCache.inCache(track.getTrackArtistMBID(), String.valueOf(url.hashCode()))) {
                continue;
            }
            // If not try to download the image.
            FanartTVManager.getInstance(getApplicationContext()).getFanartImage(track, url, response1 -> {
                mFanartCache.addFanart(track.getTrackArtistMBID(), String.valueOf(response1.url.hashCode()), response1.image);
                int fanartCount = mFanartCache.getFanartCount(response1.track.getTrackArtistMBID());
                if (fanartCount == 1) {
                    updateFanartViews();
                }
                if (mCurrentFanart == (fanartCount - 2)) {
                    mNextFanart = (mCurrentFanart + 1) % fanartCount;
                }
            }, error -> {
            });
        }
    }, new FanartFetchError() {

        @Override
        public void imageListFetchError() {
        }

        @Override
        public void fanartFetchError(MPDTrack track) {
        }
    });
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) FanartFetchError(org.gateshipone.malp.application.artworkdatabase.network.responses.FanartFetchError)

Example 3 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.

the class ArtworkManager method fetchNextBulkTrackAlbum.

/**
 * Iterates over the list of artists and downloads images for them.
 */
private void fetchNextBulkTrackAlbum() {
    Log.v(TAG, "fetchNextBulkTrackAlbum");
    boolean isEmpty;
    synchronized (mTrackList) {
        isEmpty = mTrackList.isEmpty();
    }
    while (!isEmpty) {
        Log.v(TAG, "Next track album");
        MPDTrack track;
        synchronized (mTrackList) {
            track = mTrackList.remove(0);
            mBulkProgressCallback.albumsRemaining(mTrackList.size());
        }
        mCurrentBulkTrack = track;
        // Check if image already there
        try {
            getAlbumImageForTrack(track, -1, -1, true);
        // If this does not throw the exception it already has an image.
        } catch (ImageNotFoundException e) {
            fetchAlbumImage(track);
            return;
        }
        synchronized (mTrackList) {
            isEmpty = mTrackList.isEmpty();
        }
    }
    if (mAlbumList.isEmpty()) {
        mBulkProgressCallback.finishedLoading();
    }
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)

Example 4 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack 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)

Example 5 with MPDTrack

use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack in project malp by gateship-one.

the class CurrentPlaylistAdapter method getView.

/**
 * Create the actual listview items if no reusable object is provided.
 *
 * @param position    Index of the item to create.
 * @param convertView If != null this view can be reused to optimize performance.
 * @param parent      Parent of the view
 * @return
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get MPDTrack at the given index used for this item.
    MPDTrack track = getTrack(position);
    // Check if the track was available in local data set already (or is currently fetching)
    if (track != null) {
        String trackAlbum = track.getTrackAlbum();
        VIEW_TYPES type = VIEW_TYPES.values()[getItemViewType(position)];
        // Normal track item type
        if (type == VIEW_TYPES.TYPE_TRACK_ITEM) {
            if (convertView == null) {
                // If not create a new Listitem
                convertView = new FileListItem(mContext, false);
            }
            FileListItem tracksListViewItem = (FileListItem) convertView;
            tracksListViewItem.setTrack(track, true, mContext);
            tracksListViewItem.setTrackNumber(String.valueOf(position + 1));
        } else if (type == VIEW_TYPES.TYPE_SECTION_TRACK_ITEM) {
            // Section track type.
            if (convertView == null) {
                // If not create a new Listitem
                convertView = new FileListItem(mContext, trackAlbum, false, this);
            }
            FileListItem tracksListViewItem = (FileListItem) convertView;
            tracksListViewItem.setSectionHeader(trackAlbum);
            tracksListViewItem.setTrack(track, true, mContext);
            tracksListViewItem.setTrackNumber(String.valueOf(position + 1));
            // This will prepare the view for fetching the image from the internet if not already saved in local database.
            ((FileListItem) convertView).prepareArtworkFetching(mArtworkManager, track);
            // starts the loading.
            if (mScrollSpeed == 0) {
                ((FileListItem) convertView).startCoverImageTask();
            }
        }
        if (null != mLastStatus && mLastStatus.getCurrentSongIndex() == position) {
            ((FileListItem) convertView).setPlaying(true);
        } else {
            ((FileListItem) convertView).setPlaying(false);
        }
    } else {
        // the running fetch.
        if (convertView == null) {
            // If not create a new Listitem
            convertView = new FileListItem(mContext, false);
        } else {
            FileListItem tracksListViewItem = (FileListItem) convertView;
            tracksListViewItem.setTrack(null, true, mContext);
        }
    }
    // The view that is used for the position in the list
    return convertView;
}
Also used : MPDTrack(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack) FileListItem(org.gateshipone.malp.application.listviewitems.FileListItem)

Aggregations

MPDTrack (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDTrack)25 MPDFileEntry (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDFileEntry)7 Bundle (android.os.Bundle)4 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)4 MPDDirectory (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDDirectory)4 MPDPlaylist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDPlaylist)4 AppCompatActivity (android.support.v7.app.AppCompatActivity)3 AdapterView (android.widget.AdapterView)3 AddPathToPlaylist (org.gateshipone.malp.application.callbacks.AddPathToPlaylist)3 MPDCurrentStatus (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus)3 FileListItem (org.gateshipone.malp.application.listviewitems.FileListItem)2 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)2 Bitmap (android.graphics.Bitmap)1 MenuInflater (android.view.MenuInflater)1 VolleyError (com.android.volley.VolleyError)1 ArrayList (java.util.ArrayList)1 ImageNotFoundException (org.gateshipone.malp.application.artworkdatabase.ImageNotFoundException)1 FanartFetchError (org.gateshipone.malp.application.artworkdatabase.network.responses.FanartFetchError)1 TrackAlbumFetchError (org.gateshipone.malp.application.artworkdatabase.network.responses.TrackAlbumFetchError)1 ChoosePlaylistDialog (org.gateshipone.malp.application.fragments.serverfragments.ChoosePlaylistDialog)1