mucke/lib/system/models/song_model.dart

68 lines
1.8 KiB
Dart
Raw Normal View History

2020-04-06 22:33:26 +02:00
import 'package:audio_service/audio_service.dart';
import 'package:flutter_audio_query/flutter_audio_query.dart';
2020-03-28 14:35:41 +01:00
import 'package:meta/meta.dart';
import 'package:moor/moor.dart';
import '../../domain/entities/song.dart';
import '../datasources/moor_music_data_source.dart';
2020-03-28 14:35:41 +01:00
class SongModel extends Song {
SongModel({
this.id,
@required String title,
@required String album,
@required String artist,
@required String path,
int trackNumber,
String albumArtPath,
}) : super(
title: title,
album: album,
artist: artist,
path: path,
trackNumber: trackNumber,
albumArtPath: albumArtPath,
);
factory SongModel.fromMoorSong(MoorSong moorSong) => SongModel(
title: moorSong.title,
artist: moorSong.artist,
album: moorSong.album,
path: moorSong.path,
albumArtPath: moorSong.albumArtPath,
trackNumber: moorSong.trackNumber,
);
factory SongModel.fromSongInfo(SongInfo songInfo) {
final String _trackNumber = songInfo.track;
return SongModel(
title: songInfo.title,
artist: songInfo.artist,
albumArtPath: songInfo.albumArtwork,
album: songInfo.album,
path: songInfo.filePath,
trackNumber: _trackNumber == null ? null : int.parse(_trackNumber),
);
}
2020-03-28 14:35:41 +01:00
final int id;
SongsCompanion toSongsCompanion() => SongsCompanion(
album: Value(album),
artist: Value(artist),
title: Value(title),
path: Value(path),
albumArtPath: Value(albumArtPath),
trackNumber: Value(trackNumber),
);
2020-04-06 22:33:26 +02:00
MediaItem toMediaItem() => MediaItem(
title: title,
album: album,
artist: artist,
2020-04-07 22:06:43 +02:00
artUri: 'file://$albumArtPath',
2020-04-06 22:33:26 +02:00
id: path,
);
2020-03-28 14:35:41 +01:00
}