Ajout de la vérification de l'écoute d'une musique et execution en conséquence.
continuous-integration/drone/push Build is passing Details

messagerie_lucas_test
Félix MIELCAREK 2 years ago
parent 850fb277d3
commit 2d3c90b8c7

@ -139,6 +139,20 @@ class Api {
//functional methods
Future<String> getCurrentlyPlayingTrack() async {
var url = Uri.https('api.spotify.com', 'v1/me/player/currently-playing');
var token = await _getAccessToken();
var response = await _client.get(url, headers: <String, String>{
'Authorization': '$_tokenType $token',
'Content-Type': 'application/json'
});
if (response.statusCode == 204) {
return getRecentlyPlayedTrack();
}
var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes)) as Map;
return decodedResponse['item']['id'];
}
Future<String> getRecentlyPlayedTrack() async {
var url = Uri.https(
'api.spotify.com', 'v1/me/player/recently-played', {'limit': '1'});

@ -27,6 +27,7 @@ class MyInAppBrowser extends InAppBrowser {
if (url!.origin + url.path == MyApp.api.redirectUri) {
try {
await MyApp.api.requestUserAuthorization(url);
//await MyApp.api.getPlaylists();
} on ApiException {
// TODO : add notification to show that an error occured

@ -65,7 +65,7 @@ class User {
_actualiseTrack() async {
try {
_id = await MyApp.api.getRecentlyPlayedTrack();
_id = await MyApp.api.getCurrentlyPlayingTrack();
track = await MyApp.api.getTrackInfo(_id);
} on ApiException {
// TODO : add notification to show that an error occured

Loading…
Cancel
Save