chore: Revert audioplayer changes

pull/998/head
Krille 1 year ago
parent a86a2c9749
commit 4dee111c73
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -38,8 +38,8 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
StreamSubscription? onPlayerError; StreamSubscription? onPlayerError;
String? statusText; String? statusText;
double currentPosition = 0.0; int currentPosition = 0;
double maxPosition = 1.0; double maxPosition = 0;
MatrixFile? matrixFile; MatrixFile? matrixFile;
File? audioFile; File? audioFile;
@ -113,7 +113,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 = state.inMilliseconds.toDouble(); currentPosition = ((state.inMilliseconds.toDouble() / maxPosition) *
AudioPlayerWidget.wavesCount)
.round();
}); });
if (state.inMilliseconds.toDouble() == maxPosition) { if (state.inMilliseconds.toDouble() == maxPosition) {
audioPlayer.stop(); audioPlayer.stop();
@ -149,14 +151,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 || if (eventWaveForm == null || eventWaveForm.isEmpty) {
eventWaveForm.isEmpty || return List<int>.filled(AudioPlayerWidget.wavesCount, 500);
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,7 +172,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;
@ -208,9 +208,8 @@ 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(12.0),
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
@ -241,90 +240,70 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
}, },
), ),
), ),
Expanded( const SizedBox(width: 8),
child: Stack( Row(
children: [ mainAxisSize: MainAxisSize.min,
if (waveform != null) children: [
Container( for (var i = 0; i < AudioPlayerWidget.wavesCount; i++)
height: 40, GestureDetector(
padding: const EdgeInsets.symmetric(horizontal: 24.0), onTapDown: (_) => audioPlayer?.seek(
child: Row( Duration(
children: [ milliseconds:
for (var i = 0; i < waveform.length; i++) (maxPosition / AudioPlayerWidget.wavesCount).round() *
Expanded( i,
child: Center(
child: Container(
decoration: BoxDecoration(
color: widget.color.withAlpha(64),
borderRadius: BorderRadius.circular(2),
),
height: 56 * (waveform[i] / 1024),
),
),
),
],
), ),
), ),
if (audioPlayer != null) child: Container(
SizedBox( height: 32,
height: 40, color: widget.color.withAlpha(0),
child: Slider( alignment: Alignment.center,
activeColor: widget.color, child: Opacity(
thumbColor: widget.color, opacity: currentPosition > i ? 1 : 0.5,
value: currentPosition, child: Container(
min: 0, margin: const EdgeInsets.symmetric(horizontal: 1),
max: maxPosition, decoration: BoxDecoration(
onChangeStart: (_) => audioPlayer.pause(), color: widget.color,
onChangeEnd: (_) => audioPlayer.play(), borderRadius: BorderRadius.circular(2),
onChanged: (pos) => audioPlayer.seek(
Duration(
milliseconds: pos.round(),
), ),
width: 2,
height: 32 * (waveform[i] / 1024),
), ),
), ),
), ),
], ),
), ],
), ),
Container( const SizedBox(width: 8),
alignment: Alignment.centerRight, SizedBox(
width: 42, width: 36,
child: Text( child: Text(
statusText, statusText,
style: TextStyle( style: TextStyle(
color: widget.color, color: widget.color,
fontSize: 12,
), ),
), ),
), ),
const SizedBox(width: 4), const SizedBox(width: 8),
Stack( Badge(
children: [ label: audioPlayer == null
SizedBox( ? null
width: buttonSize, : Text(
height: buttonSize,
child: InkWell(
splashColor: widget.color.withAlpha(128),
borderRadius: BorderRadius.circular(64),
onTap: audioPlayer == null ? null : _toggleSpeed,
child: Icon(Icons.mic_none_outlined, color: widget.color),
),
),
if (audioPlayer != null)
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Text(
'${audioPlayer.speed.toString()}x', '${audioPlayer.speed.toString()}x',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 9.0,
color: widget.color,
),
), ),
), backgroundColor: Theme.of(context).colorScheme.secondary,
], textColor: Theme.of(context).colorScheme.onSecondary,
child: InkWell(
splashColor: widget.color.withAlpha(128),
borderRadius: BorderRadius.circular(64),
onTap: audioPlayer == null ? null : _toggleSpeed,
child: Icon(
Icons.mic_none_outlined,
color: widget.color,
),
),
), ),
const SizedBox(width: 8),
], ],
), ),
); );

Loading…
Cancel
Save