static int try_play(sp_session *session, sp_track *t,int offset) { sp_error err; fprintf(stderr,"try play\n"); err = sp_session_player_load(session,t); if( err != SP_ERROR_OK) { fprintf(stderr,"Load failed %d\n",err); } if(!sp_track_is_loaded(t)) { if(g_track_to_be_played != t) { if(g_track_to_be_played) sp_track_release(g_track_to_be_played); g_track_to_be_played = t; //FIXME: Do I need to addref? sp_track_add_ref(g_track_to_be_played); } } else { //FIXME: Seek! // g_current_fifo_idx = (g_current_fifo_idx+1) % 2; sp_session_player_seek(session,offset); sp_session_player_play(session,true); sp_album *album = sp_track_album(t); if(album) { const byte *id = sp_album_cover(album); g_gazify.current_t = t; if(id) { sp_image *img = sp_image_create(session,id); sp_image_add_load_callback(img,&image_loaded,&g_gazify); } } g_track_to_be_played = NULL; } return err; }
boost::shared_ptr<Image> Album::GetImage() { if (IsLoading()) { return boost::shared_ptr<Image>(); } const byte* album_id = sp_album_cover( m_pAlbum, SP_IMAGE_SIZE_NORMAL); if (album_id == NULL) { return boost::shared_ptr<Image>(); } boost::shared_ptr<Image> image = m_session->CreateImage(); if (image->Load( album_id )) { return image; } else { return boost::shared_ptr<Image>(); } }
sp_image* track_get_image(sp_track* track) { sp_album* alb = NULL; sp_image* img = NULL; const void* img_id = NULL; /* Get album */ alb = sp_track_album(track); if (!alb) g_error("Can't get track album."); sp_album_add_ref(alb); if (!sp_album_is_loaded(alb)) g_error("Album not loaded."); /* Get image */ img_id = sp_album_cover(alb, SP_IMAGE_SIZE_NORMAL); if (!img_id) { /* Since the album is loaded, a NULL here indicates that there is no cover for this album. */ sp_album_release(alb); return NULL; } img = sp_image_create(g_session, img_id); sp_album_release(alb); if (!img) g_error("Can't create image."); return img; }
ListResponse<TrackInfo*>* SpotifyPlaylistContainer::listTracks( PlaylistTask* task) { ListResponse<TrackInfo*>* response = new ListResponse<TrackInfo*>(); response->setListType(ListTypeSong); ListPlaylistTrackInfo info = task->getCommandInfo().listPlaylistTrackInfo; int playlistId = info.playlist; if (playlistId > -1 && playlistId < sp_playlistcontainer_num_playlists(playlistContainer)) { bool sendName = ((info.trackInfoFlags & TrackInfoName) == TrackInfoName); bool sendArtist = ((info.trackInfoFlags & TrackInfoArtists) == TrackInfoArtists); bool sendAlbum = ((info.trackInfoFlags & TrackInfoAlbum) == TrackInfoAlbum); bool sendDuration = ((info.trackInfoFlags & TrackInfoDuration) == TrackInfoDuration); bool sendArtwork = ((info.trackInfoFlags & TrackInfoArtwork) == TrackInfoArtwork); sp_playlist* playlist = sp_playlistcontainer_playlist(playlistContainer, playlistId); int numTracks = sp_playlist_num_tracks(playlist); for (int i = 0; i < numTracks; i++) { TrackInfo* trackInfo = new TrackInfo(); trackInfo->id = i; sp_track* track = sp_playlist_track(playlist, i); if (sendName) { trackInfo->name = sp_track_name(track); } if (sendArtist) { trackInfo->numArtists = sp_track_num_artists(track); trackInfo->artists = new const char*[trackInfo->numArtists]; for (int j = 0; j < trackInfo->numArtists; j++) { trackInfo->artists[j] = sp_artist_name( sp_track_artist(track, j)); } } if (sendAlbum) { trackInfo->album = sp_album_name(sp_track_album(track)); } if (sendDuration) { trackInfo->duration = sp_track_duration(track); } if (sendArtwork) { trackInfo->artwork = sp_image_create(session, sp_album_cover(sp_track_album(track), SP_IMAGE_SIZE_NORMAL)); } response->addMember(trackInfo); } return response; } delete response; return nullptr; }
static PyObject * Album_cover(Album * self) { const byte *cover = sp_album_cover(self->_album); if (!cover) Py_RETURN_NONE; return Py_BuildValue("s#", cover, 20); }
sp_image *Track::albumImage(SpotifySession *session) const { if(isValid()) { sp_album *album = sp_track_album(m_spTrack); if (album) { const byte *id = sp_album_cover(album); return sp_image_create(session->session(), id); } } return NULL; }
sp_link * sp_link_create_from_album_cover(sp_album *album, sp_image_size size) { const byte *image_id = sp_album_cover(album, size); if ( ! image_id) { return NULL; } return sp_link_create_from_string(image_id_to_uri(image_id)); }
bool QSpotifyAlbum::updateData() { bool updated = false; bool isAvailable = sp_album_is_available(m_sp_album); sp_artist *a = sp_album_artist((m_sp_album)); QString artist; if (a) artist = QString::fromUtf8(sp_artist_name(a)); QString name = QString::fromUtf8(sp_album_name(m_sp_album)); int year = sp_album_year(m_sp_album); Type type = Type(sp_album_type(m_sp_album)); // Get cover const byte *album_cover_id = sp_album_cover(m_sp_album, SP_IMAGE_SIZE_NORMAL); if (album_cover_id != 0 && m_coverId.isEmpty()) { sp_link *link = sp_link_create_from_album_cover(m_sp_album, SP_IMAGE_SIZE_NORMAL); if (link) { char buffer[200]; int uriSize = sp_link_as_string(link, &buffer[0], 200); m_coverId = QString::fromUtf8(&buffer[0], uriSize); sp_link_release(link); updated = true; } } if (isAvailable != m_isAvailable) { m_isAvailable = isAvailable; updated = true; } if (artist != m_artist) { m_artist = artist; updated = true; } if (name != m_name) { m_name = name; updated = true; } if (year != m_year) { m_year = year; updated = true; } if (type != m_type) { m_type = type; updated = true; } return updated; }