mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-23 20:49:26 +01:00
feat: Implement web audio player
This commit is contained in:
parent
b5d849bf6f
commit
0f6b46dd82
@ -2,12 +2,15 @@ import 'dart:async';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
|
import 'package:fluffychat/components/message_download_content.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_sound/flutter_sound.dart';
|
import 'package:flutter_sound/flutter_sound.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:universal_html/prefer_universal/html.dart' as html;
|
||||||
import 'dialogs/simple_dialogs.dart';
|
import 'dialogs/simple_dialogs.dart';
|
||||||
|
import '../utils/ui_fake.dart' if (dart.library.html) 'dart:ui' as ui;
|
||||||
|
import 'matrix.dart';
|
||||||
|
|
||||||
class AudioPlayer extends StatefulWidget {
|
class AudioPlayer extends StatefulWidget {
|
||||||
final Color color;
|
final Color color;
|
||||||
@ -36,6 +39,22 @@ class _AudioPlayerState extends State<AudioPlayer> {
|
|||||||
double currentPosition = 0;
|
double currentPosition = 0;
|
||||||
double maxPosition = 0;
|
double maxPosition = 0;
|
||||||
|
|
||||||
|
String webSrcUrl;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (kIsWeb) {
|
||||||
|
ui.platformViewRegistry.registerViewFactory(
|
||||||
|
'web_audio_player',
|
||||||
|
(int viewId) => html.AudioElement()
|
||||||
|
..src = webSrcUrl
|
||||||
|
..autoplay = false
|
||||||
|
..controls = true
|
||||||
|
..style.border = 'none');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
if (flutterSound.audioState == t_AUDIO_STATE.IS_PLAYING) {
|
if (flutterSound.audioState == t_AUDIO_STATE.IS_PLAYING) {
|
||||||
@ -111,6 +130,18 @@ class _AudioPlayerState extends State<AudioPlayer> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (kIsWeb) {
|
||||||
|
if (widget.event.content['url'] is String) {
|
||||||
|
webSrcUrl = Uri.parse(widget.event.content['url'])
|
||||||
|
.getDownloadLink(Matrix.of(context).client);
|
||||||
|
return Container(
|
||||||
|
height: 50,
|
||||||
|
width: 300,
|
||||||
|
child: HtmlElementView(viewType: 'web_audio_player'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return MessageDownloadContent(widget.event, widget.color);
|
||||||
|
}
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
4
lib/utils/ui_fake.dart
Normal file
4
lib/utils/ui_fake.dart
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// ignore: camel_case_types
|
||||||
|
class platformViewRegistry {
|
||||||
|
static void registerViewFactory(String viewId, dynamic cb) {}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user