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

Time:11-10

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...

CodePudding user response:

Using the following code might help you. But I recommend you use google ExoPlayer as it has more features than MediaPlayer from android.

 MediaPlayer mp = new MediaPlayer(); 
 mp.setDataSource(context,Uri.parse("your url")); 
 mp.prepare(); 
 mp.start();

Check that for Google ExoPlayer ExoPlayer Documentation

CodePudding user response:

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/

  • Related