Skip to content

Commit

Permalink
feat: improve local audio import speed by updating audio_metadata_rea…
Browse files Browse the repository at this point in the history
…der (#1019)
  • Loading branch information
Feichtmeier authored Nov 15, 2024
1 parent 1bad15e commit ba9c0c6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
22 changes: 10 additions & 12 deletions lib/external_path/external_path_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ class ExternalPathService {
return;
}
try {
readMetadata(File(path), getImage: true).then(
(data) => _playerService.startPlaylist(
listName: path,
audios: [Audio.fromMetadata(path: path, data: data)],
),
final metadata = readMetadata(File(path), getImage: true);
_playerService.startPlaylist(
listName: path,
audios: [Audio.fromMetadata(path: path, data: metadata)],
);
} on Exception catch (e) {
printMessageInDebugMode(e);
Expand All @@ -61,11 +60,10 @@ class ExternalPathService {
try {
openFile().then((xfile) {
if (xfile?.path == null) return;
readMetadata(File(xfile!.path), getImage: true).then(
(metadata) => _playerService.startPlaylist(
listName: xfile.path,
audios: [Audio.fromMetadata(path: xfile.path, data: metadata)],
),
final metadata = readMetadata(File(xfile!.path), getImage: true);
_playerService.startPlaylist(
listName: xfile.path,
audios: [Audio.fromMetadata(path: xfile.path, data: metadata)],
);
});
} on Exception catch (e) {
Expand Down Expand Up @@ -113,7 +111,7 @@ class ExternalPathService {
audios.add(
Audio.fromMetadata(
path: path,
data: await readMetadata(
data: readMetadata(
File(e.link.replaceAll('file://', '')),
getImage: true,
),
Expand Down Expand Up @@ -160,7 +158,7 @@ class ExternalPathService {
audios.add(
Audio.fromMetadata(
path: e.file!,
data: await readMetadata(File(e.file!), getImage: true),
data: readMetadata(File(e.file!), getImage: true),
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/local_audio/local_audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ FutureOr<ImportResult> _readAudiosFromDirectory(String? directory) async {
for (final e in entities) {
try {
if (e is File && e.isValidMedia) {
final metadata = await readMetadata(e, getImage: false);
final metadata = readMetadata(e, getImage: false);
newAudios.add(Audio.fromMetadata(path: e.path, data: metadata));
}
} on Exception catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion lib/local_audio/local_cover_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LocalCoverService {
required String path,
}) async {
if (albumId.isNotEmpty == true) {
final metadata = await readMetadata(File(path), getImage: true);
final metadata = readMetadata(File(path), getImage: true);
final cover = _put(
albumId: albumId,
data: metadata.pictures
Expand Down
2 changes: 1 addition & 1 deletion lib/playlists/view/playlist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PlaylistPage extends StatelessWidget with WatchItMixin {
if (value == null) return;
final file = File.fromUri(value);
if (file.isValidMedia) {
final data = await readMetadata(file, getImage: true);
final data = readMetadata(file, getImage: true);
var audio = Audio.fromMetadata(path: file.path, data: data);
playlist?.add(audio);
}
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ packages:
dependency: "direct main"
description:
name: audio_metadata_reader
sha256: "40bd155e2ab0de725656235c51bb8441d2af49e793f0a643653801e05a693eb4"
sha256: cc575b48df1f3a5cd1586082d2e02578ce58c67d7742f7c0bfca264a03c51627
url: "https://pub.dev"
source: hosted
version: "0.0.6"
version: "0.0.8"
audio_service:
dependency: "direct main"
description:
Expand Down Expand Up @@ -969,10 +969,10 @@ packages:
dependency: transitive
description:
name: mime
sha256: "801fd0b26f14a4a58ccb09d5892c3fbdeff209594300a542492cf13fba9d247a"
sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6"
url: "https://pub.dev"
source: hosted
version: "1.0.6"
version: "2.0.0"
mockito:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:

dependencies:
animated_emoji: ^3.1.0
audio_metadata_reader: 0.0.6
audio_metadata_reader: 0.0.8
audio_service: ^0.18.12
audio_service_mpris:
git:
Expand Down

0 comments on commit ba9c0c6

Please sign in to comment.