diff --git a/lib/main.dart b/lib/main.dart index 38ef5375b..6b79f2c1b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,7 +2,6 @@ import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:desktop_notifications/desktop_notifications.dart'; import 'package:flutter/material.dart'; import 'package:media_kit/media_kit.dart'; -import 'package:metadata_god/metadata_god.dart'; import 'package:mpris_service/mpris_service.dart'; import 'package:musicpod/app/common/constants.dart'; import 'package:musicpod/musicpod.dart'; @@ -18,7 +17,6 @@ Future main() async { await YaruWindowTitleBar.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized(); MediaKit.ensureInitialized(); - MetadataGod.initialize(); final mpris = await MPRIS.create( busName: 'org.mpris.MediaPlayer2.musicpod', diff --git a/lib/service/local_audio_service.dart b/lib/service/local_audio_service.dart index 13c3f27b7..68c851065 100644 --- a/lib/service/local_audio_service.dart +++ b/lib/service/local_audio_service.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:flutter/foundation.dart'; import 'package:metadata_god/metadata_god.dart'; import 'package:mime_type/mime_type.dart'; import 'package:musicpod/app/common/constants.dart'; @@ -38,69 +39,85 @@ class LocalAudioService { _audiosController.add(true); } - final _failedImports = []; Future> init() async { - _failedImports.clear(); _directory = await readSetting(kDirectoryProperty); _directory ??= getUserDirectory('MUSIC')?.path; - if (_directory != null) { - final allFileSystemEntities = Set.from( - await _getFlattenedFileSystemEntities(path: directory!), - ); + final result = await compute(_init, directory); - final onlyFiles = []; + _audios = result.$2; - for (var fileSystemEntity in allFileSystemEntities) { - if (!await FileSystemEntity.isDirectory(fileSystemEntity.path) && - _validType(fileSystemEntity.path)) { - onlyFiles.add(fileSystemEntity); - } + _audiosController.add(true); + _directoryController.add(true); + + return result.$1; + } +} + +FutureOr<(List, Set