引入播放列表库,同时引入全新的播放控制器,以控制读库与播放模式的动作,但是功能仍在完善,需要确认部分边界问题
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
// lib/models/playlist.dart
|
||||
import 'package:qingting_player/services/audio_service.dart';
|
||||
|
||||
class Playlist {
|
||||
final String id;
|
||||
final String name;
|
||||
final PlayMode playMode;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
|
||||
Playlist({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.playMode = PlayMode.sequential,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) : createdAt = createdAt ?? DateTime.now(),
|
||||
updatedAt = updatedAt ?? DateTime.now();
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'play_mode': Playlist.playModeToString(playMode), // ⭐ 改用公开静态方法
|
||||
'created_at': createdAt.millisecondsSinceEpoch,
|
||||
'updated_at': updatedAt.millisecondsSinceEpoch,
|
||||
};
|
||||
|
||||
factory Playlist.fromJson(Map<String, dynamic> json) => Playlist(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
playMode: Playlist.stringToPlayMode(
|
||||
json['play_mode'] as String? ?? 'sequential'),
|
||||
createdAt:
|
||||
DateTime.fromMillisecondsSinceEpoch(json['created_at'] as int),
|
||||
updatedAt:
|
||||
DateTime.fromMillisecondsSinceEpoch(json['updated_at'] as int),
|
||||
);
|
||||
|
||||
Playlist copyWith({String? name, PlayMode? playMode}) => Playlist(
|
||||
id: id,
|
||||
name: name ?? this.name,
|
||||
playMode: playMode ?? this.playMode,
|
||||
createdAt: createdAt,
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
|
||||
// ⭐ 改为公开静态方法
|
||||
static String playModeToString(PlayMode mode) {
|
||||
switch (mode) {
|
||||
case PlayMode.sequential:
|
||||
return 'sequential';
|
||||
case PlayMode.repeatOne:
|
||||
return 'repeat_one';
|
||||
case PlayMode.shuffle:
|
||||
return 'shuffle';
|
||||
}
|
||||
}
|
||||
|
||||
static PlayMode stringToPlayMode(String value) {
|
||||
switch (value) {
|
||||
case 'repeat_one':
|
||||
return PlayMode.repeatOne;
|
||||
case 'shuffle':
|
||||
return PlayMode.shuffle;
|
||||
default:
|
||||
return PlayMode.sequential;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user