|
|
@ -2,6 +2,7 @@ import 'dart:async'; |
|
|
import 'dart:io'; |
|
|
import 'dart:io'; |
|
|
import 'dart:convert'; |
|
|
import 'dart:convert'; |
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart'; |
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart'; |
|
|
|
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
import 'package:spotify_sdk/spotify_sdk.dart'; |
|
|
import 'package:spotify_sdk/spotify_sdk.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'ai_service.dart'; |
|
|
import 'ai_service.dart'; |
|
|
@ -11,6 +12,10 @@ import 'package:path_provider/path_provider.dart'; |
|
|
/// OpenAI服务适配器 - 连接AiService接口与OpenAIService插件 |
|
|
/// OpenAI服务适配器 - 连接AiService接口与OpenAIService插件 |
|
|
class SpotifService { |
|
|
class SpotifService { |
|
|
bool isInitialized = false; |
|
|
bool isInitialized = false; |
|
|
|
|
|
final GetStorage _storage = GetStorage(); |
|
|
|
|
|
|
|
|
|
|
|
late String SPOTIFY_CLIENT_ID; |
|
|
|
|
|
late String SPOTIFY_REDIRECT_URL; |
|
|
|
|
|
|
|
|
/// 初始化OpenAI服务 |
|
|
/// 初始化OpenAI服务 |
|
|
Future<bool> initialize() async { |
|
|
Future<bool> initialize() async { |
|
|
@ -18,6 +23,9 @@ class SpotifService { |
|
|
await getAccessToken(); |
|
|
await getAccessToken(); |
|
|
await connectToSpotifyRemote(); |
|
|
await connectToSpotifyRemote(); |
|
|
isInitialized = true; |
|
|
isInitialized = true; |
|
|
|
|
|
final _env = _storage.read("ENV") as Map<String, String>; |
|
|
|
|
|
SPOTIFY_CLIENT_ID = _env['SPOTIFY_CLIENT_ID'] ?? ''; |
|
|
|
|
|
SPOTIFY_REDIRECT_URL = _env['SPOTIFY_REDIRECT_URL'] ?? ''; |
|
|
printInfo(info: "SpotifService----------- initialize"); |
|
|
printInfo(info: "SpotifService----------- initialize"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -28,8 +36,8 @@ class SpotifService { |
|
|
Future<void> connectToSpotifyRemote() async { |
|
|
Future<void> connectToSpotifyRemote() async { |
|
|
try { |
|
|
try { |
|
|
var result = await SpotifySdk.connectToSpotifyRemote( |
|
|
var result = await SpotifySdk.connectToSpotifyRemote( |
|
|
clientId: dotenv.env['SPOTIFY_CLIENT_ID'].toString(), |
|
|
clientId: SPOTIFY_CLIENT_ID, |
|
|
redirectUrl: dotenv.env['SPOTIFY_REDIRECT_URL'].toString(), |
|
|
redirectUrl: SPOTIFY_REDIRECT_URL, |
|
|
scope: |
|
|
scope: |
|
|
'user-read-private user-read-email streaming app-remote-control user-modify-playback-state', |
|
|
'user-read-private user-read-email streaming app-remote-control user-modify-playback-state', |
|
|
); |
|
|
); |
|
|
@ -46,8 +54,8 @@ class SpotifService { |
|
|
Future<String> getAccessToken() async { |
|
|
Future<String> getAccessToken() async { |
|
|
try { |
|
|
try { |
|
|
var authenticationToken = await SpotifySdk.getAccessToken( |
|
|
var authenticationToken = await SpotifySdk.getAccessToken( |
|
|
clientId: dotenv.env['SPOTIFY_CLIENT_ID'].toString(), |
|
|
clientId: SPOTIFY_CLIENT_ID, |
|
|
redirectUrl: dotenv.env['SPOTIFY_REDIRECT_URL'].toString(), |
|
|
redirectUrl: SPOTIFY_REDIRECT_URL, |
|
|
scope: 'app-remote-control, ' |
|
|
scope: 'app-remote-control, ' |
|
|
'user-modify-playback-state, ' |
|
|
'user-modify-playback-state, ' |
|
|
'playlist-read-private, ' |
|
|
'playlist-read-private, ' |
|
|
|