mirror of
https://github.com/amigan/calls.git
synced 2024-11-21 20:39:47 -05:00
collapse audio
This commit is contained in:
parent
486e078dfd
commit
d52c8310a3
2 changed files with 3 additions and 37 deletions
|
@ -3,43 +3,10 @@ import 'package:just_audio/just_audio.dart' as justaudio;
|
||||||
import 'audio_none.dart'
|
import 'audio_none.dart'
|
||||||
if (dart.library.io) 'audio_mediakit.dart'
|
if (dart.library.io) 'audio_mediakit.dart'
|
||||||
if (dart.library.html) 'audio_web.dart';
|
if (dart.library.html) 'audio_web.dart';
|
||||||
//import 'package:audioplayers/audioplayers.dart' as auplay;
|
|
||||||
//import 'dart:io' show Platform;
|
|
||||||
|
|
||||||
import '../pb/stillbox.pb.dart';
|
import '../pb/stillbox.pb.dart';
|
||||||
|
|
||||||
abstract class AudioDriver {
|
class JustAudioDriver {
|
||||||
Future<void> play(Call call);
|
|
||||||
Stream<justaudio.PlayerState> get playerStateStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Player {
|
|
||||||
late AudioDriver driver;
|
|
||||||
Player() {
|
|
||||||
// if (Platform.isMacOS || Platform.isIOS) {
|
|
||||||
driver = JustAudioDriver();
|
|
||||||
// } else {
|
|
||||||
// driver = AudioPlayersDriver();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> play(Call call) async {
|
|
||||||
await driver.play(call);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
class AudioPlayersDriver implements AudioDriver {
|
|
||||||
final player = auplay.AudioPlayer();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> play(Call call) {
|
|
||||||
return player.play(auplay.BytesSource(Uint8List.fromList(call.audio)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
class JustAudioDriver implements AudioDriver {
|
|
||||||
final player = justaudio.AudioPlayer();
|
final player = justaudio.AudioPlayer();
|
||||||
final initializer = AudioInitializer();
|
final initializer = AudioInitializer();
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class MainRadio extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MainRadioState extends State<MainRadio> {
|
class _MainRadioState extends State<MainRadio> {
|
||||||
Player player = Player();
|
final player = JustAudioDriver();
|
||||||
bool lcdState = false;
|
bool lcdState = false;
|
||||||
static const _lcdTimeout = 3;
|
static const _lcdTimeout = 3;
|
||||||
static const _lcdOnColor = Colors.amber;
|
static const _lcdOnColor = Colors.amber;
|
||||||
|
@ -26,13 +26,12 @@ class _MainRadioState extends State<MainRadio> {
|
||||||
Color _ledColor = Colors.black;
|
Color _ledColor = Colors.black;
|
||||||
Timer? _lcdTimer;
|
Timer? _lcdTimer;
|
||||||
SBCall? _call;
|
SBCall? _call;
|
||||||
Future<bool> completion;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final sb = Provider.of<Stillbox>(context, listen: false);
|
final sb = Provider.of<Stillbox>(context, listen: false);
|
||||||
player.driver.playerStateStream.listen((event) async {
|
player.player.playerStateStream.listen((event) async {
|
||||||
if (!event.playing &&
|
if (!event.playing &&
|
||||||
event.processingState == ProcessingState.completed) {
|
event.processingState == ProcessingState.completed) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
Loading…
Reference in a new issue