暂时把bug先处理掉了,准备尝试实现最小播放目标
This commit is contained in:
@@ -1,7 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/song_model.dart';
|
||||
|
||||
// 这是一个 ChangeNotifier,以后用来刷新底部的迷你播放条
|
||||
class Song {
|
||||
final String id;
|
||||
final String title;
|
||||
final String artist;
|
||||
final String? url;
|
||||
|
||||
Song({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.artist,
|
||||
this.url,
|
||||
});
|
||||
}
|
||||
|
||||
class AudioService extends ChangeNotifier {
|
||||
Song? _currentSong;
|
||||
bool _isPlaying = false;
|
||||
@@ -9,16 +21,20 @@ class AudioService extends ChangeNotifier {
|
||||
Song? get currentSong => _currentSong;
|
||||
bool get isPlaying => _isPlaying;
|
||||
|
||||
// 占位方法:以后这里会调用 media_kit
|
||||
void playSong(Song song) {
|
||||
_currentSong = song;
|
||||
_isPlaying = true;
|
||||
notifyListeners(); // 刷新 UI
|
||||
print('🎵 准备播放: ${song.title} - ${song.artist}');
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void togglePlay() {
|
||||
_isPlaying = !_isPlaying;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void stopPlay() {
|
||||
_currentSong = null;
|
||||
_isPlaying = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user