From b86413cda3b86fa9aec22112b7640fb559631270 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 18 Apr 2018 09:10:54 -0700 Subject: [PATCH] Add albumArtUrl to state Helps with #510 --- js/actionCreators.js | 10 ++++++++-- js/reducers/playlist.js | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/js/actionCreators.js b/js/actionCreators.js index 30f21930..5bf201ef 100644 --- a/js/actionCreators.js +++ b/js/actionCreators.js @@ -360,10 +360,16 @@ export function fetchMediaTags(file, id) { dispatch({ type: MEDIA_TAG_REQUEST_INITIALIZED, id }); return genMediaTags(file) .then(data => { - const { artist, title } = data.tags; // There's more data here, but we don't have a use for it yet: // https://github.com/aadsm/jsmediatags#shortcuts - dispatch({ type: SET_MEDIA_TAGS, artist, title, id }); + const { artist, title, picture } = data.tags; + let albumArtUrl = null; + if (picture) { + const byteArray = new Uint8Array(picture.data); + const blob = new Blob([byteArray], { type: picture.type }); + albumArtUrl = URL.createObjectURL(blob); + } + dispatch({ type: SET_MEDIA_TAGS, artist, title, albumArtUrl, id }); }) .catch(() => { dispatch({ type: MEDIA_TAG_REQUEST_FAILED, id }); diff --git a/js/reducers/playlist.js b/js/reducers/playlist.js index 2ec16f89..c766cd91 100644 --- a/js/reducers/playlist.js +++ b/js/reducers/playlist.js @@ -179,7 +179,8 @@ const playlist = (state = defaultPlaylistState, action) => { ...state.tracks[action.id], mediaTagsRequestStatus: MEDIA_TAG_REQUEST_STATUS.COMPLETE, title: action.title, - artist: action.artist + artist: action.artist, + albumArtUrl: action.albumArtUrl } } };