fix artist fragment and implement basic audio playback
This commit is contained in:
parent
e876a57d01
commit
6711c6202c
6 changed files with 55 additions and 20 deletions
|
|
@ -18,6 +18,7 @@ public class ArtistImage {
|
|||
}
|
||||
|
||||
public String toIdString() {
|
||||
if (artistName == null) return "";
|
||||
StringBuilder id = new StringBuilder(artistName);
|
||||
for (AlbumCover albumCover: albumCovers) {
|
||||
id.append(albumCover.getYear()).append(albumCover.getFilePath());
|
||||
|
|
|
|||
|
|
@ -14,14 +14,24 @@ import java.util.List;
|
|||
public class Artist implements Parcelable {
|
||||
public static final String UNKNOWN_ARTIST_DISPLAY_NAME = "Unknown Artist";
|
||||
|
||||
public final List<Album> albums;
|
||||
public List<Album> albums;
|
||||
public List<String> genres;
|
||||
|
||||
public String id;
|
||||
public String name;
|
||||
public long duration;
|
||||
public int albumCount;
|
||||
public int songCount;
|
||||
|
||||
public Artist(BaseItemDto itemDto) {
|
||||
this.id = itemDto.getId();
|
||||
this.name = itemDto.getName();
|
||||
this.duration = itemDto.getRunTimeTicks() / 10000;
|
||||
this.albumCount = itemDto.getAlbumCount() != null ? itemDto.getAlbumCount() : 0;
|
||||
this.songCount = itemDto.getSongCount() != null ? itemDto.getSongCount() : 0;
|
||||
|
||||
this.albums = new ArrayList<>();
|
||||
this.genres = itemDto.getGenres();
|
||||
}
|
||||
|
||||
public Artist() {
|
||||
|
|
@ -29,14 +39,10 @@ public class Artist implements Parcelable {
|
|||
}
|
||||
|
||||
public String getId() {
|
||||
return id != null ? id : "";
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
String name = safeGetFirstAlbum().getArtistName();
|
||||
if (MusicUtil.isArtistNameUnknown(name)) {
|
||||
return UNKNOWN_ARTIST_DISPLAY_NAME;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
@ -60,24 +66,18 @@ public class Artist implements Parcelable {
|
|||
return songs;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Album safeGetFirstAlbum() {
|
||||
return albums.isEmpty() ? new Album() : albums.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Artist artist = (Artist) o;
|
||||
|
||||
return albums != null ? albums.equals(artist.albums) : artist.albums == null;
|
||||
return id.equals(artist.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return albums != null ? albums.hashCode() : 0;
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class Song implements Parcelable {
|
|||
this.title = itemDto.getName();
|
||||
this.trackNumber = itemDto.getIndexNumber();
|
||||
this.year = itemDto.getProductionYear();
|
||||
this.duration = itemDto.getRunTimeTicks();
|
||||
this.duration = itemDto.getRunTimeTicks() / 10000;
|
||||
this.data = "";
|
||||
this.dateModified = 2;
|
||||
this.albumId = itemDto.getAlbumId();
|
||||
|
|
|
|||
|
|
@ -115,7 +115,14 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
QueryUtil.getArtist(getIntent().getExtras().getString(EXTRA_ARTIST_ID), new MediaCallback() {
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
setArtist((Artist) media.get(0));
|
||||
Artist artist = (Artist) media.get(0);
|
||||
QueryUtil.getAlbums(artist.id, new MediaCallback() {
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
artist.albums = (List<Album>) media;
|
||||
setArtist(artist);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import android.text.TextUtils;
|
|||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.loader.PlaylistLoader;
|
||||
|
|
@ -28,6 +29,8 @@ import com.kabouzeid.gramophone.model.Genre;
|
|||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
|
@ -38,7 +41,7 @@ import java.util.Locale;
|
|||
*/
|
||||
public class MusicUtil {
|
||||
public static Uri getSongFileUri(Song song) {
|
||||
return Uri.parse(song.data);
|
||||
return Uri.parse(App.getApiClient().getApiUrl() + "/Audio/" + song.id + "/stream?static=true");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.kabouzeid.gramophone.model.Song;
|
|||
|
||||
import org.jellyfin.apiclient.interaction.Response;
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
import org.jellyfin.apiclient.model.querying.ArtistsQuery;
|
||||
import org.jellyfin.apiclient.model.querying.ItemQuery;
|
||||
import org.jellyfin.apiclient.model.querying.ItemsResult;
|
||||
|
||||
|
|
@ -55,6 +56,30 @@ public class QueryUtil {
|
|||
});
|
||||
}
|
||||
|
||||
public static void getAlbums(String id, MediaCallback callback) {
|
||||
ItemQuery query = new ItemQuery();
|
||||
query.setIncludeItemTypes(new String[]{"MusicAlbum"});
|
||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
||||
query.setArtistIds(new String[]{id});
|
||||
query.setRecursive(true);
|
||||
App.getApiClient().GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult result) {
|
||||
List<Album> albums = new ArrayList<>();
|
||||
for (BaseItemDto itemDto : result.getItems()) {
|
||||
albums.add(new Album(itemDto));
|
||||
}
|
||||
|
||||
callback.onLoadMedia(albums);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void getSongs(String album, MediaCallback callback) {
|
||||
ItemQuery query = new ItemQuery();
|
||||
query.setIncludeItemTypes(new String[]{"Audio"});
|
||||
|
|
@ -80,12 +105,11 @@ public class QueryUtil {
|
|||
}
|
||||
|
||||
public static void getArtists(MediaCallback callback) {
|
||||
ItemQuery query = new ItemQuery();
|
||||
query.setIncludeItemTypes(new String[]{"MusicArtist"});
|
||||
ArtistsQuery query = new ArtistsQuery();
|
||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
||||
query.setLimit(10);
|
||||
query.setRecursive(true);
|
||||
App.getApiClient().GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
App.getApiClient().GetAlbumArtistsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult result) {
|
||||
List<Artist> artists = new ArrayList<>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue