music binding work
continuous-integration/drone/push Build is passing Details

pull/11/head
David D'ALMEIDA 2 years ago
parent dfe944faff
commit ce7dc3f8bc

@ -12,6 +12,7 @@ import { State, TapGestureHandler } from "react-native-gesture-handler";
import { RequestHandler } from "../services/spotify/spotifyRequestHandler/utils"; import { RequestHandler } from "../services/spotify/spotifyRequestHandler/utils";
import { FetchRequest } from "expo-auth-session/build/Fetch"; import { FetchRequest } from "expo-auth-session/build/Fetch";
import Music from "../Model/Music"; import Music from "../Model/Music";
import SpotifyService from "../services/spotify/spotify.service";
interface SpotProps { interface SpotProps {
spot: { name: string, sourceUrl: string, index : number }; spot: { name: string, sourceUrl: string, index : number };
@ -215,7 +216,13 @@ const MusicDetail = ({ route }) => {
// } // }
// } // }
const animationState = new Value(State.UNDETERMINED); const animationState = new Value(State.UNDETERMINED);
const playMusic = async (id: string) => {
try {
const service = new SpotifyService("BQC4k_OPQXENwmm2S8qLm9whlJT9IjeKsuG6kJNyVCSd88b0L-zOY84VqwvQxFsc9G3GvtPyUMezwxi8BBBloitzbhWX5tmTKTaLsJosGTnb7xivwNhRv0-LnNYbZWB24ZGAg0xPmDLn0yYmYlo7M_SMK5cCZdYQcZNXAuMYaI18GVXKoICBaKfCn4GcqBiRRgXyCVQnNGU4") ;
console.log("=====================================================)))))))))))))))"+id+"================================")
await service.playMusic(id);
}catch(error){}
}
return ( return (
<View style={{ flex: 1, justifyContent : 'flex-start', alignItems : 'center' }}> <View style={{ flex: 1, justifyContent : 'flex-start', alignItems : 'center' }}>
@ -237,9 +244,9 @@ const MusicDetail = ({ route }) => {
]} ]}
/> />
<Button title="Current Track" <Button title="Play Track On Device"
onPress={() => { onPress={() => {
getCurrentTrack() playMusic(currentspot.id)
// promptAsync(); // promptAsync();
}} }}
/> />

@ -1,7 +1,7 @@
import axios from "axios"; import axios from "axios";
import MusicFactory from "../../Model/factory/MusicFactory"; import MusicFactory from "../../Model/factory/MusicFactory";
import Music from "../../Model/Music"; import Music from "../../Model/Music";
import { RequestHandler } from "./spotifyRequestHandler/utils"; import { FetchOptions, RequestHandler } from "./spotifyRequestHandler/utils";
export default class SpotifyService implements IspotifyService { export default class SpotifyService implements IspotifyService {
private readonly API_URL = "https://flad-api-production.up.railway.app/api/"; private readonly API_URL = "https://flad-api-production.up.railway.app/api/";
@ -46,15 +46,29 @@ export default class SpotifyService implements IspotifyService {
return respMusic.data.items[0].track.id; return respMusic.data.items[0].track.id;
} }
public async playMusic(): Promise<string | null>{ public async playMusic(idMusic : string): Promise<void>{
var requestData :string = '/me/player/recently-played'; var requestData :string = '/me/player/play';
const respMusic = await this.spotifyRequestHandler.spotifyFetch(requestData, undefined,this.token);
if (respMusic.status != 200) { const fetchOptions: FetchOptions = {
} method: 'PUT',
if (respMusic.data.items.length <= 0) { body: {
return null; uris: [`spotify:track:${idMusic}`],
} position_ms: 0
return respMusic.data.items[0].track.id; }
};
const respMusic = await this.spotifyRequestHandler.spotifyFetch(requestData, fetchOptions,this.token);
// need to handle when
// if (respMusic.status != 200) {
// if (respMusic.status == 400 && respMusic.data.message =='need to use Spotify premium'){
// }
// }
// if(respMusic){
// console.log(respMusic);
// console.log(respMusic.data);
// }
return ;
} }
async getSpotifyCredentials() { async getSpotifyCredentials() {

@ -31,7 +31,7 @@ export class RequestHandler{
}, },
data: options.body data: options.body
}); });
console.log() // console.log(resp);
return resp; return resp;
// if ( // if (
// // @ts-ignore // // @ts-ignore

Loading…
Cancel
Save