Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
soulfood
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
charley.punshon
soulfood
Commits
d631d86b
Commit
d631d86b
authored
May 18, 2019
by
jade.woodward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Spotify can play a specific song when the app is started
only if the device has Spotify tho
parent
45d8222a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
30 deletions
+26
-30
MainActivity.java
...n/java/com/example/soulfood_assignment2/MainActivity.java
+22
-30
SpotifyClass.java
...n/java/com/example/soulfood_assignment2/SpotifyClass.java
+4
-0
No files found.
app/src/main/java/com/example/soulfood_assignment2/MainActivity.java
View file @
d631d86b
package
com
.
example
.
soulfood_assignment2
;
import
android.animation.ObjectAnimator
;
import
android.content.Intent
;
import
android.support.v4.view.ViewCompat
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.widget.EditText
;
import
android.widget.ProgressBar
;
import
com.spotify.android.appremote.api.ConnectionParams
;
...
...
@@ -33,10 +29,7 @@ public class MainActivity extends AppCompatActivity {
private
int
maxValue
;
private
int
progressValue
;
private
static
final
String
CLIENT_ID
=
"3e5fe6fc098945ccaec377241f38d829"
;
private
static
final
String
REDIRECT_URI
=
"https://cs2s.yorkdc.net"
;
// URI to application domain
private
SpotifyAppRemote
mSpotifyAppRemote
;
public
SpotifyClass
spotifyClass
;
private
static
final
int
REQUEST_CODE
=
1337
;
int
swipeStartX
=
-
50
;
//arbitrary default value
...
...
@@ -45,7 +38,6 @@ public class MainActivity extends AppCompatActivity {
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
Log
.
d
(
"Testing!!!"
,
"onCreate"
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_loading_screen
);
...
...
@@ -74,7 +66,6 @@ public class MainActivity extends AppCompatActivity {
};
thread
.
start
();
}
protected
File
doInBackground
(
Void
...
Voids
)
{
...
...
@@ -136,18 +127,30 @@ public class MainActivity extends AppCompatActivity {
};
thread
.
start
();
}
protected
void
onStart
()
{
Log
.
d
(
"Testing!!!"
,
"onStart"
);
spotifyClass
=
new
SpotifyClass
();
super
.
onStart
();
LogIn
();
}
spotifyLogIn
();
protected
void
onStop
()
{
super
.
onStop
();
SpotifyAppRemote
.
disconnect
(
spotifyClass
.
mSpotifyAppRemote
);
}
ConnectionParams
connP
=
new
ConnectionParams
.
Builder
(
CLIENT_ID
).
setRedirectUri
(
REDIRECT_URI
).
showAuthView
(
true
).
build
();
public
void
LogIn
()
{
AuthenticationRequest
.
Builder
builder
=
new
AuthenticationRequest
.
Builder
(
spotifyClass
.
CLIENT_ID
,
AuthenticationResponse
.
Type
.
TOKEN
,
spotifyClass
.
REDIRECT_URI
);
builder
.
setScopes
(
new
String
[]{
"streaming"
});
AuthenticationRequest
request
=
builder
.
build
();
AuthenticationClient
.
openLoginActivity
(
this
,
REQUEST_CODE
,
request
);
ConnectionParams
connP
=
new
ConnectionParams
.
Builder
(
spotifyClass
.
CLIENT_ID
).
setRedirectUri
(
spotifyClass
.
REDIRECT_URI
).
showAuthView
(
true
).
build
();
SpotifyAppRemote
.
connect
(
this
,
connP
,
new
Connector
.
ConnectionListener
()
{
public
void
onConnected
(
SpotifyAppRemote
spotifyAppRemote
)
{
mSpotifyAppRemote
=
spotifyAppRemote
;
spotifyClass
.
mSpotifyAppRemote
=
spotifyAppRemote
;
Log
.
d
(
"Testing!!!"
,
"Connected"
);
connected
();
...
...
@@ -155,25 +158,14 @@ public class MainActivity extends AppCompatActivity {
public
void
onFailure
(
Throwable
throwable
)
{
Log
.
e
(
"Testing!!!"
,
throwable
.
getMessage
(),
throwable
);
//Something went wrong when attempting to connect! Handle errors here
//Something went wrong when attempting to connect! Handle errors here
}
});
}
private
void
connected
(){
mSpotifyAppRemote
.
getPlayerApi
().
play
(
"spotify:playlist:37i9dQZF1DX2sUQwD7tbmL"
);
}
protected
void
onStop
()
{
super
.
onStop
();
SpotifyAppRemote
.
disconnect
(
mSpotifyAppRemote
);
}
private
void
spotifyLogIn
()
{
//
AuthenticationRequest
.
Builder
builder
=
new
AuthenticationRequest
.
Builder
(
CLIENT_ID
,
AuthenticationResponse
.
Type
.
TOKEN
,
REDIRECT_URI
);
builder
.
setScopes
(
new
String
[]{
"streaming"
});
AuthenticationRequest
request
=
builder
.
build
();
AuthenticationClient
.
openLoginActivity
(
this
,
REQUEST_CODE
,
request
);
public
void
connected
(){
Log
.
d
(
"Testing!!!"
,
"in connected method"
);
spotifyClass
.
playSong
();
}
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
intent
)
{
...
...
app/src/main/java/com/example/soulfood_assignment2/SpotifyClass.java
0 → 100644
View file @
d631d86b
package
com
.
example
.
soulfood_assignment2
;
public
class
SpotifyClass
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment