会话页面

This commit is contained in:
2022-10-26 14:05:58 +08:00
parent 099d2b4423
commit 76bd3f94fd
33 changed files with 2956 additions and 31 deletions

View File

@@ -0,0 +1,66 @@
import 'dart:async';
import 'package:flutter_plugin_record_plus/const/play_state.dart';
import 'package:flutter_plugin_record_plus/const/response.dart';
import 'package:flutter_plugin_record_plus/index.dart';
typedef PlayStateListener = void Function(PlayState playState);
typedef SoundInterruptListener = void Function();
typedef ResponseListener = void Function(RecordResponse recordResponse);
class SoundPlayer {
static final FlutterPluginRecord _recorder = FlutterPluginRecord();
static SoundInterruptListener? _soundInterruptListener;
static bool isInited = false;
static initSoundPlayer() {
if (!isInited) {
_recorder.init();
isInited = true;
}
}
static play({required String url}) {
_recorder.stopPlay();
if (_soundInterruptListener != null) {
_soundInterruptListener!();
}
_recorder.playByPath(url, 'url');
}
static stop() {
_recorder.stopPlay();
}
static dispose() {
_recorder.dispose();
}
static StreamSubscription<PlayState> playStateListener(
{required PlayStateListener listener}) =>
_recorder.responsePlayStateController.listen(listener);
static setSoundInterruptListener(SoundInterruptListener listener) {
_soundInterruptListener = listener;
}
static removeSoundInterruptListener() {
_soundInterruptListener = null;
}
static StreamSubscription<RecordResponse> responseListener(
ResponseListener listener) =>
_recorder.response.listen(listener);
static StreamSubscription<RecordResponse> responseFromAmplitudeListener(
ResponseListener listener) =>
_recorder.responseFromAmplitude.listen(listener);
static startRecord() {
_recorder.start();
}
static stopRecord() {
_recorder.stop();
}
}