mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-12 02:32:54 +01:00
chore: FIx waveforms on small screens
This commit is contained in:
parent
54985897d1
commit
12f86533a3
@ -10,7 +10,6 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
|
||||||
import 'package:fluffychat/utils/sentry_controller.dart';
|
import 'package:fluffychat/utils/sentry_controller.dart';
|
||||||
import '../../../utils/matrix_sdk_extensions.dart/event_extension.dart';
|
import '../../../utils/matrix_sdk_extensions.dart/event_extension.dart';
|
||||||
|
|
||||||
@ -20,6 +19,8 @@ class AudioPlayerWidget extends StatefulWidget {
|
|||||||
|
|
||||||
static String? currentId;
|
static String? currentId;
|
||||||
|
|
||||||
|
static const int wavesCount = 40;
|
||||||
|
|
||||||
const AudioPlayerWidget(this.event, {this.color = Colors.black, Key? key})
|
const AudioPlayerWidget(this.event, {this.color = Colors.black, Key? key})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@ -109,8 +110,9 @@ class _AudioPlayerState extends State<AudioPlayerWidget> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
statusText =
|
statusText =
|
||||||
'${state.inMinutes.toString().padLeft(2, '0')}:${(state.inSeconds % 60).toString().padLeft(2, '0')}';
|
'${state.inMinutes.toString().padLeft(2, '0')}:${(state.inSeconds % 60).toString().padLeft(2, '0')}';
|
||||||
currentPosition =
|
currentPosition = ((state.inMilliseconds.toDouble() / maxPosition) *
|
||||||
((state.inMilliseconds.toDouble() / maxPosition) * 100).round();
|
AudioPlayerWidget.wavesCount)
|
||||||
|
.round();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
onDurationChanged ??= audioPlayer.onDurationChanged.listen((max) =>
|
onDurationChanged ??= audioPlayer.onDurationChanged.listen((max) =>
|
||||||
@ -147,18 +149,18 @@ class _AudioPlayerState extends State<AudioPlayerWidget> {
|
|||||||
.tryGetMap<String, dynamic>('org.matrix.msc1767.audio')
|
.tryGetMap<String, dynamic>('org.matrix.msc1767.audio')
|
||||||
?.tryGetList<int>('waveform');
|
?.tryGetList<int>('waveform');
|
||||||
if (eventWaveForm == null) {
|
if (eventWaveForm == null) {
|
||||||
return List<int>.filled(100, 500);
|
return List<int>.filled(AudioPlayerWidget.wavesCount, 500);
|
||||||
}
|
}
|
||||||
while (eventWaveForm.length < 100) {
|
while (eventWaveForm.length < AudioPlayerWidget.wavesCount) {
|
||||||
for (var i = 0; i < eventWaveForm.length; i = i + 2) {
|
for (var i = 0; i < eventWaveForm.length; i = i + 2) {
|
||||||
eventWaveForm.insert(i, eventWaveForm[i]);
|
eventWaveForm.insert(i, eventWaveForm[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var i = 0;
|
var i = 0;
|
||||||
final step = (eventWaveForm.length / 100).round();
|
final step = (eventWaveForm.length / AudioPlayerWidget.wavesCount).round();
|
||||||
while (eventWaveForm.length > 100) {
|
while (eventWaveForm.length > AudioPlayerWidget.wavesCount) {
|
||||||
eventWaveForm.removeAt(i);
|
eventWaveForm.removeAt(i);
|
||||||
i = (i + step) % 100;
|
i = (i + step) % AudioPlayerWidget.wavesCount;
|
||||||
}
|
}
|
||||||
return eventWaveForm;
|
return eventWaveForm;
|
||||||
}
|
}
|
||||||
@ -210,19 +212,21 @@ class _AudioPlayerState extends State<AudioPlayerWidget> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
for (var i = 0; i < 100; i++)
|
for (var i = 0; i < AudioPlayerWidget.wavesCount; i++)
|
||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () => audioPlayer.seek(Duration(
|
onTap: () => audioPlayer.seek(Duration(
|
||||||
milliseconds: (maxPosition / 100).round() * i)),
|
milliseconds:
|
||||||
|
(maxPosition / AudioPlayerWidget.wavesCount)
|
||||||
|
.round() *
|
||||||
|
i)),
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
opacity: currentPosition > i ? 1 : 0.5,
|
opacity: currentPosition > i ? 1 : 0.5,
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.only(left: 2),
|
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: widget.color,
|
color: widget.color,
|
||||||
borderRadius:
|
borderRadius: BorderRadius.circular(64),
|
||||||
BorderRadius.circular(AppConfig.borderRadius),
|
|
||||||
),
|
),
|
||||||
height: 64 * (waveform[i] / 1024)),
|
height: 64 * (waveform[i] / 1024)),
|
||||||
),
|
),
|
||||||
|
@ -13,6 +13,7 @@ import 'package:wakelock/wakelock.dart';
|
|||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:fluffychat/utils/sentry_controller.dart';
|
import 'package:fluffychat/utils/sentry_controller.dart';
|
||||||
|
import 'events/audio_player.dart';
|
||||||
|
|
||||||
class RecordingDialog extends StatefulWidget {
|
class RecordingDialog extends StatefulWidget {
|
||||||
static const String recordingFileType = 'm4a';
|
static const String recordingFileType = 'm4a';
|
||||||
@ -91,12 +92,13 @@ class _RecordingDialogState extends State<RecordingDialog> {
|
|||||||
await _audioRecorder.stop();
|
await _audioRecorder.stop();
|
||||||
final path = _recordedPath;
|
final path = _recordedPath;
|
||||||
if (path == null) throw ('Recording failed!');
|
if (path == null) throw ('Recording failed!');
|
||||||
final step = amplitudeTimeline.length < 100
|
const waveCount = AudioPlayerWidget.wavesCount;
|
||||||
|
final step = amplitudeTimeline.length < waveCount
|
||||||
? 1
|
? 1
|
||||||
: (amplitudeTimeline.length / 100).round();
|
: (amplitudeTimeline.length / waveCount).round();
|
||||||
final waveform = <int>[];
|
final waveform = <int>[];
|
||||||
for (var i = 0; i < amplitudeTimeline.length; i += step) {
|
for (var i = 0; i < amplitudeTimeline.length; i += step) {
|
||||||
waveform.add((amplitudeTimeline[i] / 100 * 1024).round());
|
waveform.add((amplitudeTimeline[i] / waveCount * 1024).round());
|
||||||
}
|
}
|
||||||
Navigator.of(context, rootNavigator: false).pop<RecordingResult>(
|
Navigator.of(context, rootNavigator: false).pop<RecordingResult>(
|
||||||
RecordingResult(
|
RecordingResult(
|
||||||
|
Loading…
Reference in New Issue
Block a user