mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 03:05:14 +00:00
design: Improve design of Voice Messages and add 1.25 as speed
This commit is contained in:
parent
18054aaa66
commit
4291396f98
1 changed files with 44 additions and 35 deletions
|
@ -38,8 +38,8 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
StreamSubscription? onPlayerError;
|
StreamSubscription? onPlayerError;
|
||||||
|
|
||||||
String? statusText;
|
String? statusText;
|
||||||
int currentPosition = 0;
|
double currentPosition = 0.0;
|
||||||
double maxPosition = 0;
|
double maxPosition = 1.0;
|
||||||
|
|
||||||
MatrixFile? matrixFile;
|
MatrixFile? matrixFile;
|
||||||
File? audioFile;
|
File? audioFile;
|
||||||
|
@ -113,9 +113,7 @@ 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 = ((state.inMilliseconds.toDouble() / maxPosition) *
|
currentPosition = state.inMilliseconds.toDouble();
|
||||||
AudioPlayerWidget.wavesCount)
|
|
||||||
.round();
|
|
||||||
});
|
});
|
||||||
if (state.inMilliseconds.toDouble() == maxPosition) {
|
if (state.inMilliseconds.toDouble() == maxPosition) {
|
||||||
audioPlayer.stop();
|
audioPlayer.stop();
|
||||||
|
@ -151,12 +149,14 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
return '${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
|
return '${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> _getWaveform() {
|
List<int>? _getWaveform() {
|
||||||
final eventWaveForm = widget.event.content
|
final eventWaveForm = widget.event.content
|
||||||
.tryGetMap<String, dynamic>('org.matrix.msc1767.audio')
|
.tryGetMap<String, dynamic>('org.matrix.msc1767.audio')
|
||||||
?.tryGetList<int>('waveform');
|
?.tryGetList<int>('waveform');
|
||||||
if (eventWaveForm == null || eventWaveForm.isEmpty) {
|
if (eventWaveForm == null ||
|
||||||
return List<int>.filled(AudioPlayerWidget.wavesCount, 500);
|
eventWaveForm.isEmpty ||
|
||||||
|
eventWaveForm.length > 100) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
while (eventWaveForm.length < AudioPlayerWidget.wavesCount) {
|
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) {
|
||||||
|
@ -172,13 +172,16 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
return eventWaveForm.map((i) => i > 1024 ? 1024 : i).toList();
|
return eventWaveForm.map((i) => i > 1024 ? 1024 : i).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
late final List<int> waveform;
|
late final List<int>? waveform;
|
||||||
|
|
||||||
void _toggleSpeed() async {
|
void _toggleSpeed() async {
|
||||||
final audioPlayer = this.audioPlayer;
|
final audioPlayer = this.audioPlayer;
|
||||||
if (audioPlayer == null) return;
|
if (audioPlayer == null) return;
|
||||||
switch (audioPlayer.speed) {
|
switch (audioPlayer.speed) {
|
||||||
case 1.0:
|
case 1.0:
|
||||||
|
await audioPlayer.setSpeed(1.25);
|
||||||
|
break;
|
||||||
|
case 1.25:
|
||||||
await audioPlayer.setSpeed(1.5);
|
await audioPlayer.setSpeed(1.5);
|
||||||
break;
|
break;
|
||||||
case 1.5:
|
case 1.5:
|
||||||
|
@ -205,6 +208,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final statusText = this.statusText ??= _durationString ?? '00:00';
|
final statusText = this.statusText ??= _durationString ?? '00:00';
|
||||||
final audioPlayer = this.audioPlayer;
|
final audioPlayer = this.audioPlayer;
|
||||||
|
final waveform = this.waveform;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
@ -237,42 +241,47 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
for (var i = 0; i < AudioPlayerWidget.wavesCount; i++)
|
if (waveform != null)
|
||||||
Expanded(
|
Padding(
|
||||||
child: GestureDetector(
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
onTapDown: (_) => audioPlayer?.seek(
|
child: Row(
|
||||||
Duration(
|
children: [
|
||||||
milliseconds:
|
for (var i = 0; i < waveform.length; i++)
|
||||||
(maxPosition / AudioPlayerWidget.wavesCount)
|
Expanded(
|
||||||
.round() *
|
child: Center(
|
||||||
i,
|
child: Container(
|
||||||
),
|
decoration: BoxDecoration(
|
||||||
),
|
color: widget.color.withAlpha(64),
|
||||||
child: Container(
|
borderRadius: BorderRadius.circular(2),
|
||||||
height: 32,
|
),
|
||||||
alignment: Alignment.center,
|
height: 32 * (waveform[i] / 1024),
|
||||||
child: Opacity(
|
),
|
||||||
opacity: currentPosition > i ? 1 : 0.5,
|
|
||||||
child: Container(
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: widget.color,
|
|
||||||
borderRadius: BorderRadius.circular(64),
|
|
||||||
),
|
),
|
||||||
height: 32 * (waveform[i] / 1024),
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 28,
|
||||||
|
child: Slider.adaptive(
|
||||||
|
value: currentPosition,
|
||||||
|
min: 0,
|
||||||
|
max: maxPosition,
|
||||||
|
onChangeStart: (_) => audioPlayer?.pause(),
|
||||||
|
onChangeEnd: (_) => audioPlayer?.play(),
|
||||||
|
onChanged: (pos) => audioPlayer?.seek(
|
||||||
|
Duration(
|
||||||
|
milliseconds: pos.round(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
|
||||||
Container(
|
Container(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
width: 42,
|
width: 42,
|
||||||
|
|
Loading…
Reference in a new issue