javaandroidandroid-studiospotifyandroid-music-player

I want to add online music streaming to an existing android local music player


I have developed an android music player app. That Play music from local storage

I would like to add online streaming options like Spotify,Gana. Etc....

Im not a professional android developer I've developed the app based on other music player source code

So anyone can help me how to add Spotify api or other options...


Solution

  • Do you mean to play Spotify music in your app? This is usually not possible, because music requires authorization, but if you have an audio file, you can put it in the cloud and use the following code to play it.

    MediaPlayer mediaPlayer = new MediaPlayer(); 
    mediaPlayer.setDataSource(applicationContext, Uri.parse("music url"))
    mediaPlayer.setOnPreparedListener { it.start() }
    mediaPlayer.prepareAsync()
    

    Alternative plan

    The Spotify SDK allows your application to interact with the Spotify app running in the background as a service. The capabilities of this API include getting metadata for the currently playing track and context, issuing basic playback commands and initiating playback of tracks.

    Please refer to: https://developer.spotify.com/documentation/android/