1

I have an Android service that can play local song (I followed this tuto: https://code.tutsplus.com/tutorials/create-a-music-player-on-android-song-playback--mobile-22778) I can control the player using a MediaController (made with this tuto: https://code.tutsplus.com/tutorials/create-a-music-player-on-android-user-controls--mobile-22787)

I want to be able to play local song and Spotify song too without changing my controller and if possible using the same service. The purpose is to be able to have a waiting list that can contain local track or spotify track and the service should be able to read both.

I have the Spotify SDK and I'm able to read a song with the player that spotify offer in his SDK, but is there a way to get a streaming URL for a song and the play it with the local player using:

String url = "http://........"; // Spotify URL here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); 
mediaPlayer.start();

So the controller is synchronized even if it's a Spotify song or a local one ? If I can't get the streaming link, is there a way to use the Android MusicController with the Spotify MusicPlayer ?

Note: Every user that used the App is connected with its Spotify Account. I use fragement so the Controller is create once and then it's the same I can access the service everywhere

Maloz
  • 165
  • 1
  • 2
  • 17

1 Answers1

1

If you want to stream from Spotify you'll have to use their SDK and their player and you will not be able to use it for local songs ,so you will need to have both of them, however you can implement a service that will have both of the players, MediaPlayer and SpotifyPlayer and control the flow, but my advice is that you make them in separate services. MediaPlayer stable while Spotify is still on beta and it's highly likely that it'll get changed frequently

3ammari
  • 144
  • 2
  • 10