Skip to content

1. Controller and Model

Akshay Chacko edited this page Apr 20, 2021 · 90 revisions

Story Map

Story Map

Music Streaming

This app uses the Spotify API for Android. Spotify API allows us to not only get the publishment information about a song (title, artist, album, Spotify link, etc.), but also get calculated audio features, such as its danceability, energy, valence, and more.

Music Features & Analysis

This app uses the Spotify API to track and analyze the audio features of each song. The tracked features can be categorized as follows:

  • Mood: Danceability, Valence, Energy, Tempo
  • Properties: Loudness, Speechiness, Instrumentalness
  • Context: Liveness, Acousticness
  • Other In-depth Features: Segments, Tatums, Bars, Beats, Pitches, Timbre, and more

The major focus of our recommendation algorithm is to find songs with similar sentiments. When the recommender receives a song, it will run the music analysis on it and return other musical tracks with similar keys, BPM, and other user-specified features. Out of the features listed above, our app allows the user to filter based on key, tempo, valence, energy, and danceability.

Recommendations

The Kotlin project file is composed of numerous activities that work together to call the back-end and push it to the front-end.

This activity corresponds to activity_starting.xml, which is the main screen of the app. From here, the user either chooses to import a song from Spotify, or to pick a premade genre playlist to seed the recommender with. Each button has an onclick handler that calls the appropriate function to spawn the next activity using intent. For instance, the "Import from Spotify" button calls the importSong() function, which proceeds to load the ImportActivity. Similiarly, the genre buttons have an onclick handler that calls one of the chooseGenre() functions, which in turn loads the HiphopActivity with whatever genre the user chose.

This activity handles the case of the user wanting to import a premade playlist. NOTE: Although the name says HiphopActivity, it actually handles all genres as it is passed a playlist of the genre that the user selected. This activity has four classes: HipHopList, RockList, PopList, and DanceList. Each of these classes essentially have private variables that contain all the metadata for the chosen genre playlist, as well as a getView() function that loads this data into a ListViewAdapter for the user to interact with. In the onCreate() function of the HiphopActivity, we check what genre the user chose and pass the corresponding class (ie. DanceList) to an instantiation of the listView. There is a back button in the top left of the activity_hiphop.xml which calls the goBack() onclick handler to return to the StartingActivity. There is also a checkmark in the bottom right of the screen, which calls the choosePlaylist() onclick handler to continue on to the RecommendationActivity.

This activity corresponds with activity_import.xml and allows the user to load a song or playlist from Spotify via URL/URI, or search for one by name. There are three submit buttons on the screen, each with an onclick handler for that case. If the user chooses to load a song/playlist via Spotify URL, the submitSong() function creates a SongStore object and calls SongStore.readPlaylist() or SongStore.readSong() depending on where the user entered a playlist or song URL. If the API returns non-empty data, then we start the RecommendationActivity. If the user chooses to search for a song/playlist, the submitSongName() or submitPlaylistName() onclick handlers are called, depending on the user's input choice. Both these functions create a SongStore object and call either SongStore.submitSongName() or SongStore.submitPlaylistName(), and then starts a SearchActivity afterwards. Note: more information on the SongStore functions can be found further down in this documentation.

Handles the displaying of the user's liked songs at the end of their recommendation session. The onCreate() function creates a SongListAdapter object, and populates it with the songs that the user liked from their session. The SongListAdapter iterates over the user's liked songs, and displays the song info, album artwork, and a link to open the song in Spotify.

Handles the displaying of the user's search results and is called from the ImportActivity. The onCreate() function of the SearchActivity creates a SearchListAdapter object. This object populates each result with the metadata for that search result in the getView() function. It also attaches each result with an OnClickListener that will call the RecommendationActivity on whichever search results the user chooses.

Handles all of the back-end API calls. Interacts with the backend server by sending GET requests. Each request function is explained below.

  • readPlaylist():
      - Seed the recommender with a playlist that the user chose. Everything in between submitting a playlist and returning the recommendations happens entirely in the back-end and won't be explained here.
      - Saves the songs received by the backend recommendation list to the front end MainActivity’s songList by using the helper function getSongInfo().
  • readSong():
      - Seed the recommender with the song that the user chose. Everything in between submitting a playlist and returning the recommendations happens entirely in the back-end and won't be explained here.   - Save the songs received by the backend recommendation list to the front end MainActivity’s songList by using the helper function getSongInfo().
  • updateRec():
      - Updates the recommendations by sending whether the user liked or disliked the recommendation to the back-end.
  • updateRecWithAudioRange():
      - Updates the recommendations if the user changes their recommendation settings (ie. if the user increases the BPM range).
  • readSongWithAudioRange(), readPlaylistWithAudioRange():
      - Seeds the recommender with the settings that the user chose for BPM, danceability, valence, energy and key.
  • submitSongName(), submitPlaylistName:
      - Both functions are used for the search functionality
      - Sends the song or playlist’s name inputted by the user to the back-end and returns a list of relevant songs and playlists.

This function is where the bulk of the user interactivity lies, and corresponds with activity_recommendation.xml. The user can keeping swiping through songs, until they decide to end their session. Each time they like or dislike a song, this information is used to update the recommender before the next song is shown. They can also choose to add additional filters based on factors such as BPM, key, etc. If they do this, the recommendations will be updated to show songs that satisfy the user constraints. If at any point the user presses the end button, the MainActivity is started to display the user's final liked songs.

  • OnCreate():
      - Get the song received by the backend from the MainActivity’s songList
      - Show the relevant data (artist name, image url, song name) and play the 30 second preview if the preview for the song exists.

  • initSettingRangeBars():
      - If the setting is enabled, allow the user to choose the range of audio features to spawn the recommendation that follows the setting

  • seedRecWithLikedSong():
      - Use the current song to start the recommendation by calling the recommendation activity
      - This will allow the recommender to find the song that flows with the current song

  • settingSwitchClick():
      - Enables or disables the recommendation settings

  • OpenSpotify():
      - Opens the song in Spotify

  • endBtnClick():
      - Onclick handler for EndBtn that ends the recommendation and will move you to the final screen (MainActivity)

Clone this wiki locally