Skip to content

Commit

Permalink
[Test] try fix ios no sound
Browse files Browse the repository at this point in the history
  • Loading branch information
canxin121 committed Jul 13, 2024
1 parent 02752aa commit 589478a
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 19 deletions.
196 changes: 196 additions & 0 deletions lib/dialogs/music_fuzz_filter_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import 'dart:async';

import 'package:app_rhyme/src/rust/api/bind/mirrors.dart';
import 'package:flutter/cupertino.dart';

Future<MusicFuzzFilter?> showMusicFuzzFilterDialog(BuildContext context,
{MusicFuzzFilter? defaultFilter, bool readonly = false}) async {
return showCupertinoDialog<MusicFuzzFilter>(
context: context,
builder: (BuildContext context) =>
MusicFuzzFilterDialog(defaultFilter: defaultFilter, readonly: readonly),
);
}

class MusicFuzzFilterDialog extends StatefulWidget {
final MusicFuzzFilter? defaultFilter;
final bool readonly;

const MusicFuzzFilterDialog(
{super.key, this.defaultFilter, this.readonly = false});

@override
MusicFuzzFilterDialogState createState() => MusicFuzzFilterDialogState();
}

class MusicFuzzFilterDialogState extends State<MusicFuzzFilterDialog> {
late TextEditingController nameController;
late TextEditingController artistController;
late TextEditingController albumController;

@override
void initState() {
super.initState();
nameController =
TextEditingController(text: widget.defaultFilter?.name ?? '');
artistController = TextEditingController(
text: widget.defaultFilter?.artist.join(', ') ?? '');
albumController =
TextEditingController(text: widget.defaultFilter?.album ?? '');
}

@override
Widget build(BuildContext context) {
final Brightness brightness = MediaQuery.of(context).platformBrightness;
final bool isDarkMode = brightness == Brightness.dark;

String title;
if (widget.readonly) {
title = '音乐筛选';
} else if (widget.defaultFilter != null) {
title = "编辑筛选条件";
} else {
title = '创建筛选条件';
}

return CupertinoAlertDialog(
title: Text(
title,
style: TextStyle(
color: isDarkMode ? CupertinoColors.white : CupertinoColors.black,
),
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: CupertinoTextField(
controller: nameController,
placeholder: '音乐名字',
readOnly: widget.readonly,
style: TextStyle(
color:
isDarkMode ? CupertinoColors.white : CupertinoColors.black,
),
placeholderStyle: TextStyle(
color: isDarkMode
? CupertinoColors.systemGrey
: CupertinoColors.systemGrey2,
),
decoration: BoxDecoration(
color: isDarkMode
? CupertinoColors.darkBackgroundGray
: CupertinoColors.white,
borderRadius: BorderRadius.circular(5.0),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: CupertinoTextField(
controller: artistController,
placeholder: '艺术家(多个用逗号分隔)',
readOnly: widget.readonly,
maxLines: widget.readonly ? null : 1,
style: TextStyle(
color:
isDarkMode ? CupertinoColors.white : CupertinoColors.black,
),
placeholderStyle: TextStyle(
color: isDarkMode
? CupertinoColors.systemGrey
: CupertinoColors.systemGrey2,
),
decoration: BoxDecoration(
color: isDarkMode
? CupertinoColors.darkBackgroundGray
: CupertinoColors.white,
borderRadius: BorderRadius.circular(5.0),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: CupertinoTextField(
controller: albumController,
placeholder: '专辑',
readOnly: widget.readonly,
maxLines: widget.readonly ? null : 1,
style: TextStyle(
color:
isDarkMode ? CupertinoColors.white : CupertinoColors.black,
),
placeholderStyle: TextStyle(
color: isDarkMode
? CupertinoColors.systemGrey
: CupertinoColors.systemGrey2,
),
decoration: BoxDecoration(
color: isDarkMode
? CupertinoColors.darkBackgroundGray
: CupertinoColors.white,
borderRadius: BorderRadius.circular(5.0),
),
),
),
],
),
actions: <CupertinoDialogAction>[
if (!widget.readonly)
CupertinoDialogAction(
child: Text(
'取消',
style: TextStyle(
color: isDarkMode
? CupertinoColors.systemGrey2
: CupertinoColors.activeBlue,
),
),
onPressed: () {
Navigator.of(context).pop();
},
),
if (!widget.readonly)
CupertinoDialogAction(
isDefaultAction: true,
onPressed: () {
if (artistController.text.isNotEmpty) {
Navigator.of(context).pop(MusicFuzzFilter(
name: nameController.text,
artist: artistController.text
.split(',')
.map((e) => e.trim())
.toList(),
album: albumController.text,
));
}
},
child: Text(
'完成',
style: TextStyle(
color: isDarkMode
? CupertinoColors.systemGrey2
: CupertinoColors.activeBlue,
),
),
),
if (widget.readonly)
CupertinoDialogAction(
isDefaultAction: true,
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'关闭',
style: TextStyle(
color: isDarkMode
? CupertinoColors.systemGrey2
: CupertinoColors.activeBlue,
),
),
),
],
);
}
}
39 changes: 22 additions & 17 deletions lib/pages/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,25 @@ class _SearchMusicAggregatorPageState extends State<SearchMusicAggregatorPage>
MediaQuery.of(context).platformBrightness == Brightness.dark;
return Column(
children: [
const SafeArea(
child: SizedBox(
height: 0,
)),
// 搜索框
Padding(
padding: const EdgeInsets.all(8.0),
child: SafeArea(
child: CupertinoSearchTextField(
style: TextStyle(
color: isDarkMode
? CupertinoColors.white
: const Color.fromRGBO(0, 0, 0, 1),
).useSystemChineseFont(),
controller: _inputContentController,
onSubmitted: (String value) {
if (value.isNotEmpty) {
_pagingController.refresh();
}
},
),
child: CupertinoSearchTextField(
style: TextStyle(
color: isDarkMode
? CupertinoColors.white
: const Color.fromRGBO(0, 0, 0, 1),
).useSystemChineseFont(),
controller: _inputContentController,
onSubmitted: (String value) {
if (value.isNotEmpty) {
_pagingController.refresh();
}
},
)),
Expanded(
child: PagedListView.separated(
Expand Down Expand Up @@ -217,11 +219,14 @@ class _SearchMusicListState extends State<SearchMusicListPage>

return Column(
children: [
const SafeArea(
child: SizedBox(
height: 0,
)),
// 搜索框
Padding(
padding: const EdgeInsets.all(8.0),
child: SafeArea(
child: CupertinoSearchTextField(
child: CupertinoSearchTextField(
style: TextStyle(
color: isDarkMode ? CupertinoColors.white : CupertinoColors.black,
).useSystemChineseFont(),
Expand All @@ -231,7 +236,7 @@ class _SearchMusicListState extends State<SearchMusicListPage>
_pagingController.refresh();
}
},
)),
),
),
Expanded(
child: PagedGridView(
Expand Down
10 changes: 8 additions & 2 deletions lib/types/music_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ class MusicContainer {
currentQuality.value = playInfo!.quality;

if (playInfo!.uri.contains("http")) {
if (Platform.isIOS || Platform.isMacOS) {
if ((Platform.isIOS || Platform.isMacOS) &&
((playInfo!.quality.format != null &&
playInfo!.quality.format!.contains("flac")) ||
(playInfo!.quality.short.contains("flac")))) {
audioSource = ProgressiveAudioSource(Uri.parse(playInfo!.uri),
tag: _toMediaItem(),
options: const ProgressiveAudioSourceOptions(
Expand All @@ -188,7 +191,10 @@ class MusicContainer {
AudioSource.uri(Uri.parse(playInfo!.uri), tag: _toMediaItem());
}
} else {
if (Platform.isIOS || Platform.isMacOS) {
if ((Platform.isIOS || Platform.isMacOS) &&
((playInfo!.quality.format != null &&
playInfo!.quality.format!.contains("flac")) ||
(playInfo!.quality.short.contains("flac")))) {
audioSource = ProgressiveAudioSource(Uri.file(playInfo!.uri),
tag: _toMediaItem(),
options: const ProgressiveAudioSourceOptions(
Expand Down

0 comments on commit 589478a

Please sign in to comment.