Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BrainzPlayer datasources improvements #1539

Merged
merged 20 commits into from
Jul 23, 2021
Merged

Conversation

MonkeyDo
Copy link
Contributor

@MonkeyDo MonkeyDo commented Jul 1, 2021

This PR changes a few things with how we play music with BrainzPlayer:

  • Instead of trying to play a track with each datasource until one works, we check if any of the datasources will be able to play the track, and if not we skip it.
    That was a dumb idea and broke our fallback strategy of trying to play on any of the datasources it could.

  • The previous functionality of determining the source of a listen and finding a usable datasource is improved and partly moved from the BrainzPlayer component to two new methods in the DataSource interface: isListenFromThisService and canSearchAndPlayTracks

  • we also reduce the verbosity of warnings, removing the "We couldn't find a matching song on any music service we tried" messages

  • while adding a new toast notification with the song title when we change track

  • we ensure that nothing happens with the player until a direct user interaction to play a song:

    • don't take any action until a flag is set by a user action, including if there is any error with the datasources (previously an error while setting up datasources could trigger playing the next track in the list even if the user didn't ask to play in the first place)
    • don't render anything if a datasource hasn't been selected to play (rendering iframes before a track is played sometimes creates problems) This broke the Youtube player whose iframe needs to be initialized first even if it is not yet in use
  • finally, we add a helpful message when no service is registered to search for and play songs.
    Suggestions welcome on the wording !
    This may or may not be relevant depending on how the whole Youtube auth things goes.
    image

Implement two methods on each source to 1. determine if a track was played from that service and 2. determine if that datasource can be used to search and play a track
Otherwise skip to the next song without any message
Each datasource returns null in the render method  when not activated or not selected
when no datasource can be used to search for songs
@MonkeyDo MonkeyDo marked this pull request as draft July 2, 2021 16:28
We have to create the iframe on load (even if we are not currently using this datasource), otherwise the  youtube player does not get initialized correctly for later use
My previous attempts were optimistic; we do definitely need to try with the next datasource if the first one failed.
Throttling the calls to trackInfoChange (youtube calls it twice in succession) and show title on screen in an 'info' toast.
@MonkeyDo MonkeyDo marked this pull request as ready for review July 16, 2021 16:14
Comment on lines 265 to 266
const { onCurrentListenChange } = this.props;
onCurrentListenChange(listen);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moved up to the beginning of the function

@@ -280,44 +295,6 @@ export default class BrainzPlayer extends React.Component<
});
};

getSourceIndexByListenData = (listen: Listen | JSPFTrack): number => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved to the datasources themselves that now implement an isListenFromThisService method

// Try playing the listen with the next dataSource
this.playListen(currentListen, currentDataSourceIndex + 1);
} else {
this.handleWarning(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just too annoying.

{artist && ` — ${artist}`}
</>
);
this.handleInfoMessage(message);
Copy link
Contributor Author

@MonkeyDo MonkeyDo Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show a notification with the song title on a blue background.
I also want to implement (in another PR) native browser notifications, with this home-made notification as a fallback.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up on that feature in PR #1561

};

// eslint-disable-next-line react/sort-comp
throttledTrackInfoChange = _throttle(this.trackInfoChange, 2000, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Youtube player was calling this method twice in short succession when loading a song.

Comment on lines +446 to +449
const hasDatasourceToSearch =
this.dataSources.findIndex((ds) =>
ds.current?.canSearchAndPlayTracks()
) !== -1;
Copy link
Contributor Author

@MonkeyDo MonkeyDo Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and the associated message line 468) might or might not be useful depending on wether we have a default player (like youtube using API keys) or if they all require auth. It does appear for a flash we the page loads, but suppose it doesn't hurt much to have clear indications in any case.
Associated ticket: https://tickets.metabrainz.org/browse/LB-907

Instead of trying blindly, we can check if there is a possibility a datasource can attempt to play the track (looking at you SoundCloud…) and skip it if it can't.
@MonkeyDo MonkeyDo merged commit 1c89208 into master Jul 23, 2021
@MonkeyDo MonkeyDo deleted the monkey-idle-brainzplayer branch July 23, 2021 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant