fix: 调整播放器样式,修改快速切换 AudioPlayer 无法正确释放的问题

master
Spark 6 days ago
parent bbf70c81c6
commit fc613ee961

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 299 KiB

@ -6,11 +6,11 @@ import 'package:music_player_miao/models/universal_bean.dart';
import '../models/getInfo_bean.dart';
import '../models/login_bean.dart';
const String _LoginURL = 'http://flyingpig.fun:10010/users/login';
const String _LogoutURL = 'http://flyingpig.fun:10010/users/logout';
const String _SetupURL = 'http://flyingpig.fun:10010/email/register';
const String _verificationURL = 'http://flyingpig.fun:10010/email/verificationCode';
const String _GetInfoURL = 'http://flyingpig.fun:10010/users/info';
const String _LoginURL = 'http://8.210.250.29:10010/users/login';
const String _LogoutURL = 'http://8.210.250.29:10010/users/logout';
const String _SetupURL = 'http://8.210.250.29:10010/email/register';
const String _verificationURL = 'http://8.210.250.29:10010/email/verificationCode';
const String _GetInfoURL = 'http://8.210.250.29:10010/users/info';
///
class LoginApiClient {

@ -3,8 +3,8 @@ import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import '../models/universal_bean.dart';
const String _changeNameURL = 'http://flyingpig.fun:10010/users/username';
const String _changeHeaderURL = 'http://flyingpig.fun:10010/users/avatar';
const String _changeNameURL = 'http://8.210.250.29:10010/users/username';
const String _changeHeaderURL = 'http://8.210.250.29:10010/users/avatar';
class ChangeApiClient {
final Dio dio = Dio();

@ -3,7 +3,7 @@
import 'package:dio/dio.dart';
import 'package:music_player_miao/models/universal_bean.dart';
const String _CollectionURL = 'http://flyingpig.fun:10010/collections';
const String _CollectionURL = 'http://8.210.250.29:10010/collections';
class CollectionApiMusic {
final Dio dio = Dio();

@ -4,7 +4,7 @@
import 'package:dio/dio.dart';
import 'package:music_player_miao/models/universal_bean.dart';
const String _LikesURL = 'http://flyingpig.fun:10010/likes';
const String _LikesURL = 'http://8.210.250.29:10010/likes';
class LikesApiMusic {
final Dio dio = Dio();

@ -4,10 +4,10 @@ import '../common_widget/Song_widegt.dart';
import '../models/getMusicList_bean.dart';
import '../models/getRank_bean.dart';
const String _getMusic1 = 'http://flyingpig.fun:10010/musics/1';
const String _getMusic2 = 'http://flyingpig.fun:10010/musics/2';
const String _getMusic3 = 'http://flyingpig.fun:10010/musics/3';
const String _getSongDetail = 'http://flyingpig.fun:10010/musics';
const String _getMusic1 = 'http://8.210.250.29:10010/musics/1';
const String _getMusic2 = 'http://8.210.250.29:10010/musics/2';
const String _getMusic3 = 'http://8.210.250.29:10010/musics/3';
const String _getSongDetail = 'http://8.210.250.29:10010/musics';
///
class GetMusic {
@ -62,7 +62,7 @@ class GetMusicDetail {
Future<Song> getMusicDetail({required int songId, required String Authorization}) async {
try {
// songId URL
final String url = 'http://flyingpig.fun:10010/musics/$songId'; // API
final String url = 'http://8.210.250.29:10010/musics/$songId'; // API
// GET
Response response = await dio.get(

@ -2,7 +2,7 @@ import 'package:dio/dio.dart';
import '../models/getRank_bean.dart';
const String _getRank = 'http://flyingpig.fun:10010/musics/rank-list';
const String _getRank = 'http://8.210.250.29:10010/musics/rank-list';
///
class GetRank {
final Dio dio = Dio();

@ -6,8 +6,8 @@ import 'package:music_player_miao/models/universal_bean.dart';
import '../models/getComment_bean.dart';
import '../models/search_bean.dart';
const String _SearchURL = 'http://flyingpig.fun:10010/musics/search';
const String _postComment = 'http://flyingpig.fun:10010/comments';
const String _SearchURL = 'http://8.210.250.29:10010/musics/search';
const String _postComment = 'http://8.210.250.29:10010/comments';
///
class SearchMusic {
final Dio dio = Dio();

@ -7,7 +7,7 @@ import 'dart:io';
import 'package:path/path.dart';
const String _ReleaseURL = 'http://flyingpig.fun:10010/musics';
const String _ReleaseURL = 'http://8.210.250.29:10010/musics';
///
class ReleaseApi {

@ -5,15 +5,15 @@ import 'package:music_player_miao/models/songlist_bean.dart';
import '../models/getAllSongs_bean.dart';
import '../models/universal_bean.dart';
import 'package:music_player_miao/models/getMyWorks.dart';
const String _SonglistURL = 'http://flyingpig.fun:10010/songlists';
const String _MyWorksURL = 'http://flyingpig.fun:10010/musics/upload-music';
const String _SonglistURL = 'http://8.210.250.29:10010/songlists';
const String _MyWorksURL = 'http://8.210.250.29:10010/musics/upload-music';
class SonglistApi {
final Dio dio = Dio();
///
Future<MyMusicListBean> getAllSongs({required int id, required String Authorization}) async {
String urlWithId = 'http://flyingpig.fun:10010/songlist-musics/$id/music-list';
String urlWithId = 'http://8.210.250.29:10010/songlist-musics/$id/music-list';
Response response = await dio.get(urlWithId,
options: Options(headers: {
'Authorization': Authorization,

@ -1,65 +0,0 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
class PasswordManager {
static const String PREFS_KEY = 'stored_password';
late SharedPreferences _prefs;
//
static final PasswordManager _instance = PasswordManager._internal();
factory PasswordManager() {
return _instance;
}
PasswordManager._internal();
//
Future<void> init() async {
_prefs = await SharedPreferences.getInstance();
}
//
Future<void> savePassword(String username, String password) async {
final Map<String, String> credentials = {
'username': username,
'password': password,
};
await _prefs.setString(PREFS_KEY, json.encode(credentials));
}
//
Map<String, String>? getStoredCredentials() {
final String? storedData = _prefs.getString(PREFS_KEY);
if (storedData != null) {
final Map<String, String> decoded = json.decode(storedData);
return {
'username': decoded['username'] as String,
'password': decoded['password'] as String,
};
}
return null;
}
//
bool hasStoredPassword() {
return _prefs.containsKey(PREFS_KEY);
}
//
Future<void> removePassword() async {
await _prefs.remove(PREFS_KEY);
}
//
String? getStoredUsername() {
final credentials = getStoredCredentials();
return credentials?['username'];
}
//
String? getStoredPassword() {
final credentials = getStoredCredentials();
return credentials?['password'];
}
}

@ -25,7 +25,6 @@ class _BeginViewState extends State<BeginView> with TickerProviderStateMixin {
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
@ -39,7 +38,7 @@ class _BeginViewState extends State<BeginView> with TickerProviderStateMixin {
backgroundColor: Colors.transparent,
resizeToAvoidBottomInset: false,
body: ScrollConfiguration(
behavior: ScrollBehavior().copyWith(
behavior: const ScrollBehavior().copyWith(
physics: const NeverScrollableScrollPhysics(),
),
child: Column(

@ -8,7 +8,6 @@ import 'package:music_player_miao/view/main_tab_view/main_tab_view.dart';
import '../../api/api_client.dart';
import '../../common/color_extension.dart';
import '../../common/password_manager.dart';
import '../../models/getInfo_bean.dart';
import '../../models/login_bean.dart';
import '../../widget/my_text_field.dart';
@ -27,7 +26,6 @@ class _LoginVState extends State<LoginV> {
bool signInRequired = false;
IconData iconPassword = CupertinoIcons.eye_fill;
bool obscurePassword = true;
final passwordManager = Get.put(PasswordManager());
@override
Widget build(BuildContext context) {
@ -80,13 +78,22 @@ class _LoginVState extends State<LoginV> {
child: TextButton(
onPressed: () async {
try {
Get.dialog(
Center(
child: CircularProgressIndicator(
backgroundColor: Colors.grey[200],
),
),
barrierDismissible: false, //
);
LoginBean bean = await LoginApiClient().login(
email: nameController.text,
password: passwordController.text,
);
if (bean.code == 200) {
passwordManager.savePassword(nameController.text, passwordController.text);
Get.to(() => const MainTabView());
Get.back();
Get.off(() => const MainTabView());
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Center(
@ -113,9 +120,12 @@ class _LoginVState extends State<LoginV> {
.getInfo(
Authorization: AppData().currentToken);
} else {
Get.back();
throw Exception("账号或密码错误");
}
} catch (error) {
Get.back();
print(error.toString());
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Center(

@ -91,7 +91,7 @@ class _MainTabViewState extends State<MainTabView> with SingleTickerProviderStat
width: 32,
height: 32,
),
text: "个人",
text: "我的",
),
],
),

@ -7,10 +7,7 @@ import '../../view_model/home_view_model.dart';
import '../api/api_music_likes.dart';
import '../api/api_collection.dart';
import '../common/download_manager.dart';
import '../api/api_music_list.dart';
import '../api/api_collection.dart';
import '../common_widget/Song_widegt.dart';
import '../models/getMusicList_bean.dart';
import '../view/commend_view.dart';
import '../models/universal_bean.dart';
@ -30,7 +27,7 @@ class MusicView extends StatefulWidget {
State<MusicView> createState() => _MusicViewState();
}
class _MusicViewState extends State<MusicView> {
class _MusicViewState extends State<MusicView> with SingleTickerProviderStateMixin {
final homeVM = Get.put(HomeViewModel());
bool _isDisposed = false;
AppData appData = AppData();
@ -57,8 +54,42 @@ class _MusicViewState extends State<MusicView> {
List<bool> likes = [];
List<bool> collection = [];
late AnimationController _rotationController;
bool _isLoading = false;
@override
void initState() {
super.initState();
currentSongIndex = widget.initialSongIndex;
playerInit();
_initializeAsync();
_rotationController = AnimationController(
duration: const Duration(seconds: 20),
vsync: this,
);
// 2.
_audioPlayer.playerStateStream.listen((state) {
if (state.playing) {
//
_rotationController.repeat();
} else {
//
_rotationController.stop(canceled: false);
}
});
}
@override
void dispose() {
_isDisposed = true;
_audioPlayer.dispose();
_rotationController.dispose();
super.dispose();
}
Future<void> _fetchSonglistData() async {
setState(() {
for (int i = 0; i < widget.songList.length; i++) {
@ -86,7 +117,8 @@ class _MusicViewState extends State<MusicView> {
try {
//
unawaited(_audioPlayer.stop());
await _audioPlayer.stop();
_rotationController.reset();
// Check for local file first
final localSong = downloadManager.getLocalSong(currentSongIndex);
@ -186,8 +218,10 @@ class _MusicViewState extends State<MusicView> {
void playOrPause() async {
if (_audioPlayer.playing) {
await _audioPlayer.pause();
_rotationController.stop(canceled: false);
} else {
await _audioPlayer.play();
_rotationController.repeat();
}
setState(() {});
}
@ -222,21 +256,6 @@ class _MusicViewState extends State<MusicView> {
await _updateCurrentSong();
}
@override
void initState() {
super.initState();
currentSongIndex = widget.initialSongIndex;
playerInit();
_initializeAsync();
}
@override
void dispose() {
_isDisposed = true;
_audioPlayer.dispose();
super.dispose();
}
void _changeCurrentSong(int index) {
if (!_isDisposed) {
setState(() {
@ -245,6 +264,36 @@ class _MusicViewState extends State<MusicView> {
});
}
}
Widget _buildRotatingAlbumCover() {
return RotationTransition(
turns: _rotationController,
child: Stack(
alignment: Alignment.center,
children: [
Positioned(
child: ClipRRect(
child: Image.network(
widget.songList[currentSongIndex].artistPic,
width: 225,
height: 225,
fit: BoxFit.cover,
),
),
),
ClipRRect(
child: Image.asset(
"assets/img/music_Ellipse.png",
width: 350,
height: 350,
fit: BoxFit.cover,
),
),
],
),
);
}
@override
Widget build(BuildContext context) {
return Container(
@ -335,31 +384,7 @@ class _MusicViewState extends State<MusicView> {
height: 80,
),
Center(
child: Stack(
alignment: Alignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.asset(
"assets/img/music_Ellipse.png",
width: 320,
height: 320,
fit: BoxFit.cover,
),
),
Positioned(
child: ClipRRect(
borderRadius: BorderRadius.circular(80),
child: Image.network(
widget.songList[currentSongIndex].artistPic,
width: 230,
height: 230,
fit: BoxFit.cover,
),
),
)
],
),
child: _buildRotatingAlbumCover(),
),
const SizedBox(
height: 60,

Loading…
Cancel
Save