chore: Display normal Slider when no waveform provided in audioplayer
This commit is contained in:
parent
5321a3768d
commit
cd611aedc4
1 changed files with 35 additions and 29 deletions
|
|
@ -179,12 +179,12 @@ 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 || eventWaveForm.isEmpty) {
|
||||||
return List<int>.filled(AudioPlayerWidget.wavesCount, 500);
|
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) {
|
||||||
|
|
@ -200,7 +200,7 @@ 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;
|
||||||
|
|
@ -229,12 +229,13 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
waveform = _getWaveform();
|
_waveform = _getWaveform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
final waveform = _waveform;
|
||||||
|
|
||||||
final statusText = this.statusText ??= _durationString ?? '00:00';
|
final statusText = this.statusText ??= _durationString ?? '00:00';
|
||||||
final audioPlayer = this.audioPlayer;
|
final audioPlayer = this.audioPlayer;
|
||||||
|
|
@ -290,34 +291,35 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
if (waveform != null)
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
Padding(
|
||||||
child: Row(
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
children: [
|
child: Row(
|
||||||
for (var i = 0;
|
children: [
|
||||||
i < AudioPlayerWidget.wavesCount;
|
for (var i = 0;
|
||||||
i++)
|
i < AudioPlayerWidget.wavesCount;
|
||||||
Expanded(
|
i++)
|
||||||
child: Container(
|
Expanded(
|
||||||
height: 32,
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.symmetric(
|
height: 32,
|
||||||
horizontal: 1,
|
alignment: Alignment.center,
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 1,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: i < wavePosition
|
||||||
|
? widget.color
|
||||||
|
: widget.color.withAlpha(128),
|
||||||
|
borderRadius: BorderRadius.circular(64),
|
||||||
|
),
|
||||||
|
height: 32 * (waveform[i] / 1024),
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: i < wavePosition
|
|
||||||
? widget.color
|
|
||||||
: widget.color.withAlpha(128),
|
|
||||||
borderRadius: BorderRadius.circular(64),
|
|
||||||
),
|
|
||||||
height: 32 * (waveform[i] / 1024),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 32,
|
height: 32,
|
||||||
child: Slider(
|
child: Slider(
|
||||||
|
|
@ -325,8 +327,12 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
widget.event.room.client.userID
|
widget.event.room.client.userID
|
||||||
? theme.colorScheme.onPrimary
|
? theme.colorScheme.onPrimary
|
||||||
: theme.colorScheme.primary,
|
: theme.colorScheme.primary,
|
||||||
activeColor: Colors.transparent,
|
activeColor: waveform == null
|
||||||
inactiveColor: Colors.transparent,
|
? widget.color
|
||||||
|
: Colors.transparent,
|
||||||
|
inactiveColor: waveform == null
|
||||||
|
? widget.color.withAlpha(128)
|
||||||
|
: Colors.transparent,
|
||||||
max: maxPosition,
|
max: maxPosition,
|
||||||
value: currentPosition,
|
value: currentPosition,
|
||||||
onChanged: (position) => audioPlayer == null
|
onChanged: (position) => audioPlayer == null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue