Commit 8a7d98a4 authored by jade.woodward's avatar jade.woodward

Stuff to play from Spotify

will now play a specific Spotify song by id and a method to pause
details on how to use to follow in email
parent 5b0705b3
...@@ -32,7 +32,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -32,7 +32,7 @@ public class MainActivity extends AppCompatActivity {
private int maxValue; private int maxValue;
private int progressValue; private int progressValue;
public SpotifyClass spotifyClass; public static SpotifyClass spotifyClass;
private static final int REQUEST_CODE = 1337; private static final int REQUEST_CODE = 1337;
int swipeStartX = -50; //arbitrary default value int swipeStartX = -50; //arbitrary default value
...@@ -131,36 +131,6 @@ public class MainActivity extends AppCompatActivity { ...@@ -131,36 +131,6 @@ public class MainActivity extends AppCompatActivity {
thread.start(); thread.start();
} }
/*Connector.ConnectionListener mConnectionListener = new Connector.ConnectionListener() {
@Override
public void onConnected(SpotifyAppRemote spotifyAppRemote) {
spotifyClass.mSpotifyAppRemote = spotifyAppRemote;
// setup all the things
}
@Override
public void onFailure(Throwable error) {
if (error instanceof NotLoggedInException || error instanceof UserNotAuthorizedException) {
// Show login button and trigger the login flow from auth library when clicked
} else if (error instanceof CouldNotFindSpotifyApp) {
// Show button to download Spotify
}
}
};
@Override
protected void onStart() {
super.onStart();
SpotifyAppRemote.disconnect(spotifyClass.mSpotifyAppRemote);
SpotifyAppRemote.connect(this, spotifyClass.connectionParams, mConnectionListener);
}
@Override
protected void onStop() {
super.onStop();
SpotifyAppRemote.disconnect(spotifyClass.mSpotifyAppRemote);
}*/
protected void onStart() { protected void onStart() {
spotifyClass = new SpotifyClass(); spotifyClass = new SpotifyClass();
...@@ -170,9 +140,12 @@ public class MainActivity extends AppCompatActivity { ...@@ -170,9 +140,12 @@ public class MainActivity extends AppCompatActivity {
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
SpotifyAppRemote.disconnect(spotifyClass.mSpotifyAppRemote); //SpotifyAppRemote.disconnect(spotifyClass.mSpotifyAppRemote);
} }
/*
* log into spotify using the spotify app logged in on the phone
*/
public void LogIn() { public void LogIn() {
AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(spotifyClass.CLIENT_ID, AuthenticationResponse.Type.TOKEN, spotifyClass.REDIRECT_URI); AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(spotifyClass.CLIENT_ID, AuthenticationResponse.Type.TOKEN, spotifyClass.REDIRECT_URI);
builder.setScopes(new String[]{"streaming"}); builder.setScopes(new String[]{"streaming"});
...@@ -196,9 +169,10 @@ public class MainActivity extends AppCompatActivity { ...@@ -196,9 +169,10 @@ public class MainActivity extends AppCompatActivity {
}); });
} }
/*
* this method is run when the app connects to spotify
*/
public void connected(){ public void connected(){
Log.d("Testing!!!", "in connected method");
spotifyClass.playSong();
} }
protected void onActivityResult(int requestCode, int resultCode, Intent intent) { protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
......
...@@ -31,27 +31,28 @@ public class SpotifyClass { ...@@ -31,27 +31,28 @@ public class SpotifyClass {
ConnectionParams connectionParams = new ConnectionParams.Builder(CLIENT_ID).setRedirectUri(REDIRECT_URI).showAuthView(true).build(); ConnectionParams connectionParams = new ConnectionParams.Builder(CLIENT_ID).setRedirectUri(REDIRECT_URI).showAuthView(true).build();
private final ErrorCallback mErrorCallback = new ErrorCallback() { /*
@Override * takes in a spotify id (just get it straight from the database)
public void onError(Throwable throwable) { * plays it
SpotifyClass.this.logError(throwable, "Boom!"); */
} public void playSong(String id) {
}; String uri = "spotify:track:" + id;
private void logError(Throwable throwable, String msg) { playUri(uri);
Log.e("Testing", msg, throwable);
} }
public void playSong() { /*
playUri("spotify:track:0XoTveGaTn2AWeoLScrXmq"); * pauses the current spotify track
subscribeToPlayerState(); */
public void pauseSong() {
mSpotifyAppRemote.getPlayerApi().pause();
} }
/*
* the bit that actually plays stuff
*/
private void playUri(String uri) { private void playUri(String uri) {
Log.d("Testing!", uri); mSpotifyAppRemote.getPlayerApi().pause();
//mSpotifyAppRemote.getPlayerApi().pause();
mSpotifyAppRemote.getPlayerApi() mSpotifyAppRemote.getPlayerApi()
.play(uri) .play(uri)
.setResultCallback(new CallResult.ResultCallback<Empty>() { .setResultCallback(new CallResult.ResultCallback<Empty>() {
...@@ -61,12 +62,12 @@ public class SpotifyClass { ...@@ -61,12 +62,12 @@ public class SpotifyClass {
} }
}) })
.setErrorCallback(mErrorCallback); .setErrorCallback(mErrorCallback);
}
private void logMessage(String msg ) {
Log.d("Testing!!", msg);
} }
/*
* idk what the rest of these methods do really
*/
private void subscribeToPlayerState() { private void subscribeToPlayerState() {
// Subscribe to PlayerState // Subscribe to PlayerState
mSpotifyAppRemote.getPlayerApi().subscribeToPlayerState().setEventCallback(new Subscription.EventCallback<PlayerState>() { mSpotifyAppRemote.getPlayerApi().subscribeToPlayerState().setEventCallback(new Subscription.EventCallback<PlayerState>() {
...@@ -81,5 +82,19 @@ public class SpotifyClass { ...@@ -81,5 +82,19 @@ public class SpotifyClass {
}); });
} }
private final ErrorCallback mErrorCallback = new ErrorCallback() {
@Override
public void onError(Throwable throwable) {
SpotifyClass.this.logError(throwable, "Boom!");
}
};
private void logError(Throwable throwable, String msg) {
Log.e("Testing", msg, throwable);
}
private void logMessage(String msg ) {
Log.d("Testing!!", msg);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment