Skip to content

Commit

Permalink
Finish Equalize
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasLixo committed Nov 22, 2024
1 parent 811872b commit 2867b7d
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 183 deletions.
2 changes: 1 addition & 1 deletion lib/app/app_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:get/get_navigation/get_navigation.dart';
import 'package:get/get_utils/src/extensions/internacionalization.dart';
import 'package:get/state_manager.dart';
import 'package:get/instance_manager.dart';
import 'package:player_hub/app/app_bindings.dart';
import 'package:player_hub/app/routes/app_bindings.dart';
import 'package:player_hub/app/routes/app_routes.dart';
import 'package:player_hub/app/routes/app_pages.dart';
import 'package:player_hub/app/core/types/app_translations.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/app/core/enums/array_image_types.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enum ArrayImageTypes {
low,
// low,
high;
}
77 changes: 39 additions & 38 deletions lib/app/core/static/app_manifest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ abstract class AppManifest {
// ==================================================
static Future<Uint8List> getImageArray({
required int id,
ArrayImageTypes type = ArrayImageTypes.low,
ArrayImageTypes type = ArrayImageTypes.high,
}) async {
late File file;

switch (type) {
case ArrayImageTypes.low:
file = File('${AppShared.documentDir.path}/${id}_64.jpg');
break;
case ArrayImageTypes.high:
file = File('${AppShared.documentDir.path}/${id}_256.jpg');
break;
}
//
// switch (type) {
// case ArrayImageTypes.low:
// file = File('${AppShared.documentDir.path}/${id}_64.jpg');
// break;
// case ArrayImageTypes.high:
// file = File('${AppShared.documentDir.path}/${id}_256.jpg');
// break;
// }
file = File('${AppShared.documentDir.path}/${id}_256.jpg');

return file.readAsBytes();
}
Expand All @@ -39,19 +40,20 @@ abstract class AppManifest {
required int id,
required ArrayImageTypes type,
}) async {
final File fileLow = File('${AppShared.documentDir.path}/${id}_64.jpg');
// final File fileLow = File('${AppShared.documentDir.path}/${id}_64.jpg');
final File fileHigh = File('${AppShared.documentDir.path}/${id}_256.jpg');

if (!await fileLow.exists() || !await fileHigh.exists()) {
if (/* !await fileLow.exists() || */ !await fileHigh.exists()) {
await _generateImageFile(id: id);
}

switch (type) {
case ArrayImageTypes.low:
return fileLow.path;
case ArrayImageTypes.high:
return fileHigh.path;
}
// switch (type) {
// case ArrayImageTypes.low:
// return fileLow.path;
// case ArrayImageTypes.high:
// return fileHigh.path;
// }
return fileHigh.path;
}

// ==================================================
Expand All @@ -60,17 +62,17 @@ abstract class AppManifest {
}) async {
final OnAudioQuery audioQuery = OnAudioQuery();

final File fileLow = File('${AppShared.documentDir.path}/${id}_64.jpg');
// final File fileLow = File('${AppShared.documentDir.path}/${id}_64.jpg');
final File fileHigh = File('${AppShared.documentDir.path}/${id}_256.jpg');

final List<Uint8List?> dataResults = await Future.wait([
audioQuery.queryArtwork(
id,
ArtworkType.AUDIO,
format: ArtworkFormat.JPEG,
size: 64,
quality: 100,
),
// audioQuery.queryArtwork(
// id,
// ArtworkType.AUDIO,
// format: ArtworkFormat.JPEG,
// size: 64,
// quality: 100,
// ),
audioQuery.queryArtwork(
id,
ArtworkType.AUDIO,
Expand All @@ -79,28 +81,27 @@ abstract class AppManifest {
quality: 100,
),
]);
final Uint8List? dataLow = dataResults[0];
// final Uint8List? dataLow = dataResults[0];
final Uint8List? dataHigh = dataResults[1];

if (dataLow != null &&
dataLow.isNotEmpty &&
dataHigh != null &&
dataHigh.isNotEmpty) {
await fileLow.writeAsBytes(dataLow);
if ( // dataLow != null &&
// dataLow.isNotEmpty &&
dataHigh != null && dataHigh.isNotEmpty) {
// await fileLow.writeAsBytes(dataLow);
await fileHigh.writeAsBytes(dataHigh);
} else {
final String randomImageColor =
_imageColors[Random().nextInt(_imageColors.length)];

final ByteData imageDataLow =
await rootBundle.load('assets/images/low_poly_$randomImageColor.jpg');
final Uint8List imageBytesLow = imageDataLow.buffer.asUint8List();
// final ByteData imageDataLow =
// await rootBundle.load('assets/images/low_poly_$randomImageColor.jpg');
// final Uint8List imageBytesLow = imageDataLow.buffer.asUint8List();

final ByteData imageDataHigh = await rootBundle
.load('assets/images/high_poly_$randomImageColor.jpg');
final Uint8List imageBytesHigh = imageDataHigh.buffer.asUint8List();

await fileLow.writeAsBytes(imageBytesLow);
// await fileLow.writeAsBytes(imageBytesLow);
await fileHigh.writeAsBytes(imageBytesHigh);
}
}
Expand All @@ -110,10 +111,10 @@ abstract class AppManifest {
required int id,
required Uint8List bytes,
}) async {
final File fileLow = File('${AppShared.documentDir.path}/${id}_64.jpg');
// final File fileLow = File('${AppShared.documentDir.path}/${id}_64.jpg');
final File fileHigh = File('${AppShared.documentDir.path}/${id}_256.jpg');

await fileLow.writeAsBytes(bytes);
// await fileLow.writeAsBytes(bytes);
await fileHigh.writeAsBytes(bytes);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/app/pages/details/details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ class _DetailsPageState extends State<DetailsPage>
? Image.memory(
currentImage,
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width,
width: Get.width,
height: Get.width,
)
: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width,
width: Get.width,
height: Get.width,
),
),
const Space(
Expand Down
28 changes: 15 additions & 13 deletions lib/app/pages/equalizer/equalize_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,28 @@ import 'package:player_hub/app/core/static/app_shared.dart';
import 'package:player_hub/app/core/types/app_functions.dart';

class EqualizerController extends GetxController with AppFunctions {
late List<int> bandLevelRange;
late List<int> bandCenterFrequencies;
Rx<List<int>?> bandLevelRange = Rxn<List<int>>();
Rx<List<int>?> bandCenterFrequencies = Rxn<List<int>>();

final PlayerController playerController = Get.find<PlayerController>();

@override
void onInit() {
super.onInit();

_initializeBands();

playerController.audioPlayer.androidAudioSessionIdStream
.listen((int? id) async {
await _initializeEqualizer(id ?? 0);
});
}

Future<void> _initializeBands() async {
final List<List<int>> dataResults = await Future.wait([
EqualizerFlutter.getBandLevelRange(),
EqualizerFlutter.getCenterBandFreqs(),
]);
bandLevelRange = dataResults[0];
bandCenterFrequencies = dataResults[1];
}

Future<void> _initializeEqualizer(int id) async {
await EqualizerFlutter.init(id);
await EqualizerFlutter.open(id);
await EqualizerFlutter.setAudioSessionId(id);

await initializeBand();

for (int i = 0; i < 5; i++) {
await EqualizerFlutter.setBandLevel(
i,
Expand All @@ -49,7 +40,18 @@ class EqualizerController extends GetxController with AppFunctions {
);
}

Future<void> initializeBand() async {
try {
bandLevelRange.value = await EqualizerFlutter.getBandLevelRange();
bandCenterFrequencies.value = await EqualizerFlutter.getCenterBandFreqs();
} catch (e) {
bandLevelRange.value = null;
bandCenterFrequencies.value = null;
}
}

Future<void> toggleEqualizer(bool value) async {
await initializeBand();
await AppShared.setShared(
SharedAttributes.equalizeMode,
value,
Expand Down
104 changes: 59 additions & 45 deletions lib/app/pages/equalizer/equalizer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class EqualizerPage extends GetView<EqualizerController> with AppFunctions {

@override
Widget build(BuildContext context) {
() async {
if (controller.bandLevelRange.value == null ||
controller.bandCenterFrequencies.value == null) {
await controller.initializeBand();
}
};

return Scaffold(
backgroundColor: AppColors.current().background,
appBar: AppBar(
Expand Down Expand Up @@ -51,52 +58,59 @@ class EqualizerPage extends GetView<EqualizerController> with AppFunctions {
],
),
body: SafeArea(
child: Column(
children: <Widget>[
ListTile(
title: Text(
'setting_reset'.tr,
style: Theme.of(context).textTheme.bodyLarge,
),
trailing: GestureDetector(
onTap: () async {
await AppShared.setShared(
SharedAttributes.frequency,
SharedAttributes.frequency.value,
);
},
child: Icon(
Icons.refresh,
size: 32,
color: AppColors.current().text,
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'equalizer_frequency1'.tr,
style: Theme.of(context).textTheme.labelMedium,
child: Obx(() {
if (controller.bandLevelRange.value != null &&
controller.bandCenterFrequencies.value != null) {
return Column(
children: <Widget>[
ListTile(
title: Text(
'setting_reset'.tr,
style: Theme.of(context).textTheme.bodyLarge,
),
Text(
'equalizer_frequency2'.tr,
style: Theme.of(context).textTheme.labelMedium,
trailing: GestureDetector(
onTap: () async {
await AppShared.setShared(
SharedAttributes.frequency,
SharedAttributes.frequency.value,
);
},
child: Icon(
Icons.refresh,
size: 32,
color: AppColors.current().text,
),
),
],
),
),
Obx(() {
return _customEQ(
context,
enabled: AppShared.getShared(SharedAttributes.equalizeMode),
bandLevelRange: controller.bandLevelRange,
);
})
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'equalizer_frequency1'.tr,
style: Theme.of(context).textTheme.labelMedium,
),
Text(
'equalizer_frequency2'.tr,
style: Theme.of(context).textTheme.labelMedium,
),
],
),
),
Obx(() {
return _customEQ(
context,
enabled: AppShared.getShared(SharedAttributes.equalizeMode),
bandLevelRange: controller.bandLevelRange.value!,
);
})
],
);
}

return const SizedBox.shrink();
}),
),
);
}
Expand All @@ -113,7 +127,7 @@ class EqualizerPage extends GetView<EqualizerController> with AppFunctions {
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: controller.bandCenterFrequencies.map((freq) {
children: controller.bandCenterFrequencies.value!.map((freq) {
return _buildSliderBand(
context,
enabled: enabled,
Expand Down
Loading

0 comments on commit 2867b7d

Please sign in to comment.