v2.41 — Issue #3: Musik-Download im Hintergrund (flutter_background_service)
- flutter_background_service ^5.0.0 hinzugefügt - AndroidManifest: FOREGROUND_SERVICE_DATA_SYNC Permission - main.dart: Background Service mit configure() initialisiert - _onServiceStart(): Service-Callback für Foreground-Garantie - DownloadService._startBackgroundService(): Foreground Service vor Download - DownloadService._stopBackgroundService(): Stopp nach Batch/Single - Integration in _resetStatus, downloadBatch, downloadVonUrl
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:flutter_background_service/flutter_background_service.dart';
|
||||
import '../models/song.dart';
|
||||
import '../database/db_helper.dart';
|
||||
import '../utils/audio_validator.dart';
|
||||
@@ -66,13 +67,46 @@ class DownloadService extends ChangeNotifier {
|
||||
_aktuellerTitel = null;
|
||||
_fehler = null;
|
||||
_abbruchCompleter = Completer<void>();
|
||||
_startBackgroundService();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Issue #3: Foreground Service starten – hält App im Hintergrund aktiv
|
||||
void _startBackgroundService() {
|
||||
try {
|
||||
final svc = FlutterBackgroundService();
|
||||
svc.isRunning().then((running) {
|
||||
if (!running) {
|
||||
svc.startService();
|
||||
}
|
||||
});
|
||||
debugPrint('🔵 Background Service gestartet');
|
||||
} catch (e) {
|
||||
debugPrint('Background Service Start fehlgeschlagen: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Issue #3: Foreground Service stoppen
|
||||
void _stopBackgroundService() {
|
||||
try {
|
||||
final svc = FlutterBackgroundService();
|
||||
svc.isRunning().then((running) {
|
||||
if (running) {
|
||||
svc.invoke('stopService');
|
||||
}
|
||||
});
|
||||
debugPrint('🔴 Background Service gestoppt');
|
||||
} catch (e) {
|
||||
debugPrint('Background Service Stop fehlgeschlagen: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Song von YouTube herunterladen
|
||||
Future<Song?> downloadVonUrl(String url) async {
|
||||
_resetStatus();
|
||||
return _downloadEinzeln(url);
|
||||
final result = await _downloadEinzeln(url);
|
||||
if (!_ladt) _stopBackgroundService();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Mehrere URLs/Playlists nacheinander mit Cooldown
|
||||
@@ -147,6 +181,7 @@ class DownloadService extends ChangeNotifier {
|
||||
}
|
||||
notifyListeners();
|
||||
_completeNotification(erfolgreich, urls.length, abgebrochen: sollAbbrechen);
|
||||
_stopBackgroundService();
|
||||
MeloLogger().zustand('download_batch_ende', {
|
||||
'erfolgreich': erfolgreich,
|
||||
'gesamt': urls.length,
|
||||
|
||||
Reference in New Issue
Block a user