fix: Flutter sound

This commit is contained in:
Christian Pauly 2020-11-14 14:47:40 +01:00
parent 7e6e23e8c5
commit dc1bfd594b
8 changed files with 138 additions and 96 deletions

View File

@ -1 +1 @@
dd448b9c97933af58f6a55258c72b577 50490a6c8b8edc222bf5a068ab13e251

View File

@ -37,49 +37,45 @@ PODS:
- file_picker (0.0.1): - file_picker (0.0.1):
- DKImagePickerController/PhotoGallery - DKImagePickerController/PhotoGallery
- Flutter - Flutter
- Firebase/CoreOnly (6.26.0): - Firebase/CoreOnly (6.33.0):
- FirebaseCore (= 6.7.2) - FirebaseCore (= 6.10.3)
- Firebase/Messaging (6.26.0): - Firebase/Messaging (6.33.0):
- Firebase/CoreOnly - Firebase/CoreOnly
- FirebaseMessaging (~> 4.4.1) - FirebaseMessaging (~> 4.7.0)
- firebase_core (0.5.0-1): - firebase_core (0.5.2):
- Firebase/CoreOnly (~> 6.26.0) - Firebase/CoreOnly (~> 6.33.0)
- Flutter - Flutter
- firebase_messaging (7.0.3): - firebase_messaging (7.0.3):
- Firebase/CoreOnly (~> 6.26.0) - Firebase/CoreOnly (~> 6.33.0)
- Firebase/Messaging (~> 6.26.0) - Firebase/Messaging (~> 6.33.0)
- firebase_core - firebase_core
- Flutter - Flutter
- FirebaseAnalyticsInterop (1.5.0) - FirebaseCore (6.10.3):
- FirebaseCore (6.7.2): - FirebaseCoreDiagnostics (~> 1.6)
- FirebaseCoreDiagnostics (~> 1.3) - GoogleUtilities/Environment (~> 6.7)
- FirebaseCoreDiagnosticsInterop (~> 1.2) - GoogleUtilities/Logger (~> 6.7)
- GoogleUtilities/Environment (~> 6.5)
- GoogleUtilities/Logger (~> 6.5)
- FirebaseCoreDiagnostics (1.7.0): - FirebaseCoreDiagnostics (1.7.0):
- GoogleDataTransport (~> 7.4) - GoogleDataTransport (~> 7.4)
- GoogleUtilities/Environment (~> 6.7) - GoogleUtilities/Environment (~> 6.7)
- GoogleUtilities/Logger (~> 6.7) - GoogleUtilities/Logger (~> 6.7)
- nanopb (~> 1.30906.0) - nanopb (~> 1.30906.0)
- FirebaseCoreDiagnosticsInterop (1.2.0) - FirebaseInstallations (1.7.0):
- FirebaseInstallations (1.3.0): - FirebaseCore (~> 6.10)
- FirebaseCore (~> 6.6) - GoogleUtilities/Environment (~> 6.7)
- GoogleUtilities/Environment (~> 6.6) - GoogleUtilities/UserDefaults (~> 6.7)
- GoogleUtilities/UserDefaults (~> 6.6)
- PromisesObjC (~> 1.2) - PromisesObjC (~> 1.2)
- FirebaseInstanceID (4.3.4): - FirebaseInstanceID (4.8.0):
- FirebaseCore (~> 6.6) - FirebaseCore (~> 6.10)
- FirebaseInstallations (~> 1.0) - FirebaseInstallations (~> 1.6)
- GoogleUtilities/Environment (~> 6.5) - GoogleUtilities/Environment (~> 6.7)
- GoogleUtilities/UserDefaults (~> 6.5) - GoogleUtilities/UserDefaults (~> 6.7)
- FirebaseMessaging (4.4.1): - FirebaseMessaging (4.7.1):
- FirebaseAnalyticsInterop (~> 1.5) - FirebaseCore (~> 6.10)
- FirebaseCore (~> 6.6) - FirebaseInstanceID (~> 4.7)
- FirebaseInstanceID (~> 4.3) - GoogleUtilities/AppDelegateSwizzler (~> 6.7)
- GoogleUtilities/AppDelegateSwizzler (~> 6.5) - GoogleUtilities/Environment (~> 6.7)
- GoogleUtilities/Environment (~> 6.5) - GoogleUtilities/Reachability (~> 6.7)
- GoogleUtilities/Reachability (~> 6.5) - GoogleUtilities/UserDefaults (~> 6.7)
- GoogleUtilities/UserDefaults (~> 6.5)
- Protobuf (>= 3.9.2, ~> 3.9) - Protobuf (>= 3.9.2, ~> 3.9)
- Flutter (1.0.0) - Flutter (1.0.0)
- flutter_keyboard_visibility (0.0.1): - flutter_keyboard_visibility (0.0.1):
@ -91,8 +87,10 @@ PODS:
- OLMKit - OLMKit
- flutter_secure_storage (3.3.1): - flutter_secure_storage (3.3.1):
- Flutter - Flutter
- flutter_sound (0.0.1): - "flutter_sound (6.4.2+1)":
- Flutter - Flutter
- mobile-ffmpeg-audio (= 4.3.1.LTS)
- "TauEngine (= 6.4.2+1)"
- FMDB (2.7.5): - FMDB (2.7.5):
- FMDB/standard (= 2.7.5) - FMDB/standard (= 2.7.5)
- FMDB/standard (2.7.5) - FMDB/standard (2.7.5)
@ -117,6 +115,7 @@ PODS:
- GoogleUtilities/Logger - GoogleUtilities/Logger
- image_picker (0.0.1): - image_picker (0.0.1):
- Flutter - Flutter
- mobile-ffmpeg-audio (4.3.1.LTS)
- nanopb (1.30906.0): - nanopb (1.30906.0):
- nanopb/decode (= 1.30906.0) - nanopb/decode (= 1.30906.0)
- nanopb/encode (= 1.30906.0) - nanopb/encode (= 1.30906.0)
@ -173,6 +172,7 @@ PODS:
- sqlite3/perf-threadsafe - sqlite3/perf-threadsafe
- sqlite3/rtree - sqlite3/rtree
- SwiftyGif (5.3.0) - SwiftyGif (5.3.0)
- "TauEngine (6.4.2+1)"
- url_launcher (0.0.1): - url_launcher (0.0.1):
- Flutter - Flutter
- webview_flutter (0.0.1): - webview_flutter (0.0.1):
@ -209,16 +209,15 @@ SPEC REPOS:
- DKImagePickerController - DKImagePickerController
- DKPhotoGallery - DKPhotoGallery
- Firebase - Firebase
- FirebaseAnalyticsInterop
- FirebaseCore - FirebaseCore
- FirebaseCoreDiagnostics - FirebaseCoreDiagnostics
- FirebaseCoreDiagnosticsInterop
- FirebaseInstallations - FirebaseInstallations
- FirebaseInstanceID - FirebaseInstanceID
- FirebaseMessaging - FirebaseMessaging
- FMDB - FMDB
- GoogleDataTransport - GoogleDataTransport
- GoogleUtilities - GoogleUtilities
- mobile-ffmpeg-audio
- nanopb - nanopb
- OLMKit - OLMKit
- PromisesObjC - PromisesObjC
@ -227,6 +226,7 @@ SPEC REPOS:
- SQLCipher - SQLCipher
- sqlite3 - sqlite3
- SwiftyGif - SwiftyGif
- TauEngine
EXTERNAL SOURCES: EXTERNAL SOURCES:
android_path_provider: android_path_provider:
@ -282,26 +282,25 @@ SPEC CHECKSUMS:
DKImagePickerController: b5eb7f7a388e4643264105d648d01f727110fc3d DKImagePickerController: b5eb7f7a388e4643264105d648d01f727110fc3d
DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179 DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179
file_picker: 3e6c3790de664ccf9b882732d9db5eaf6b8d4eb1 file_picker: 3e6c3790de664ccf9b882732d9db5eaf6b8d4eb1
Firebase: 7cf5f9c67f03cb3b606d1d6535286e1080e57eb6 Firebase: 8db6f2d1b2c5e2984efba4949a145875a8f65fe5
firebase_core: 00e54a4744164a6b5a250b96dd1ad5afaba7a342 firebase_core: 350ba329d1641211bc6183a3236893cafdacfea7
firebase_messaging: 666d9994651b1ecf8c582b52dd913f3fa58c17ef firebase_messaging: 0aea2cd5885b65e19ede58ee3507f485c992cc75
FirebaseAnalyticsInterop: 3f86269c38ae41f47afeb43ebf32a001f58fcdae FirebaseCore: d889d9e12535b7f36ac8bfbf1713a0836a3012cd
FirebaseCore: f42e5e5f382cdcf6b617ed737bf6c871a6947b17
FirebaseCoreDiagnostics: 770ac5958e1372ce67959ae4b4f31d8e127c3ac1 FirebaseCoreDiagnostics: 770ac5958e1372ce67959ae4b4f31d8e127c3ac1
FirebaseCoreDiagnosticsInterop: 296e2c5f5314500a850ad0b83e9e7c10b011a850 FirebaseInstallations: 466c7b4d1f58fe16707693091da253726a731ed2
FirebaseInstallations: 6f5f680e65dc374397a483c32d1799ba822a395b FirebaseInstanceID: bd3ffc24367f901a43c063b36c640b345a4a5dd1
FirebaseInstanceID: cef67c4967c7cecb56ea65d8acbb4834825c587b FirebaseMessaging: 5eca4ef173de76253352511aafef774caa1cba2a
FirebaseMessaging: 29543feb343b09546ab3aa04d008ee8595b43c44
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069 flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743 flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
flutter_olm: be36ebeb6388f7d7b3097d39feaf459a3cad2091 flutter_olm: be36ebeb6388f7d7b3097d39feaf459a3cad2091
flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec
flutter_sound: 0e8163ceac1e00eb6d894e2ae4641ba726a2c479 flutter_sound: 0ab66750f6d5a83198c54d343a9b34b58a5ff86d
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
GoogleDataTransport: f56af7caa4ed338dc8e138a5d7c5973e66440833 GoogleDataTransport: f56af7caa4ed338dc8e138a5d7c5973e66440833
GoogleUtilities: 7f2f5a07f888cdb145101d6042bc4422f57e70b3 GoogleUtilities: 7f2f5a07f888cdb145101d6042bc4422f57e70b3
image_picker: 9c3312491f862b28d21ecd8fdf0ee14e601b3f09 image_picker: 9c3312491f862b28d21ecd8fdf0ee14e601b3f09
mobile-ffmpeg-audio: adc36047b8032bc0f8e5c4e6ab7cb110189d9b37
nanopb: 59317e09cf1f1a0af72f12af412d54edf52603fc nanopb: 59317e09cf1f1a0af72f12af412d54edf52603fc
native_imaging: 633687fc14422729cc67ed80c3435e359ef7a92b native_imaging: 633687fc14422729cc67ed80c3435e359ef7a92b
OLMKit: 4ee0159d63feeb86d836fdcfefe418e163511639 OLMKit: 4ee0159d63feeb86d836fdcfefe418e163511639
@ -319,6 +318,7 @@ SPEC CHECKSUMS:
sqlite3: 8f7d2078ae27778699a622a94b853285793422a2 sqlite3: 8f7d2078ae27778699a622a94b853285793422a2
sqlite3_flutter_libs: 5651f8ff48e3b44d910863c4ea5916085b1b245f sqlite3_flutter_libs: 5651f8ff48e3b44d910863c4ea5916085b1b245f
SwiftyGif: e466e86c660d343357ab944a819a101c4127cb40 SwiftyGif: e466e86c660d343357ab944a819a101c4127cb40
TauEngine: 9b2bd3acc575cea2c77b91a16c34c52751da3935
url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef
webview_flutter: d2b4d6c66968ad042ad94cbb791f5b72b4678a96 webview_flutter: d2b4d6c66968ad042ad94cbb791f5b72b4678a96

View File

@ -275,6 +275,7 @@
"${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework", "${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework",
"${BUILT_PRODUCTS_DIR}/SQLCipher/SQLCipher.framework", "${BUILT_PRODUCTS_DIR}/SQLCipher/SQLCipher.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyGif/SwiftyGif.framework", "${BUILT_PRODUCTS_DIR}/SwiftyGif/SwiftyGif.framework",
"${BUILT_PRODUCTS_DIR}/TauEngine/TauEngine.framework",
"${BUILT_PRODUCTS_DIR}/android_path_provider/android_path_provider.framework", "${BUILT_PRODUCTS_DIR}/android_path_provider/android_path_provider.framework",
"${BUILT_PRODUCTS_DIR}/disk_space/disk_space.framework", "${BUILT_PRODUCTS_DIR}/disk_space/disk_space.framework",
"${BUILT_PRODUCTS_DIR}/file_picker/file_picker.framework", "${BUILT_PRODUCTS_DIR}/file_picker/file_picker.framework",
@ -282,7 +283,6 @@
"${BUILT_PRODUCTS_DIR}/flutter_local_notifications/flutter_local_notifications.framework", "${BUILT_PRODUCTS_DIR}/flutter_local_notifications/flutter_local_notifications.framework",
"${BUILT_PRODUCTS_DIR}/flutter_olm/flutter_olm.framework", "${BUILT_PRODUCTS_DIR}/flutter_olm/flutter_olm.framework",
"${BUILT_PRODUCTS_DIR}/flutter_secure_storage/flutter_secure_storage.framework", "${BUILT_PRODUCTS_DIR}/flutter_secure_storage/flutter_secure_storage.framework",
"${BUILT_PRODUCTS_DIR}/flutter_sound/flutter_sound.framework",
"${BUILT_PRODUCTS_DIR}/image_picker/image_picker.framework", "${BUILT_PRODUCTS_DIR}/image_picker/image_picker.framework",
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework", "${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
"${BUILT_PRODUCTS_DIR}/native_imaging/native_imaging.framework", "${BUILT_PRODUCTS_DIR}/native_imaging/native_imaging.framework",
@ -310,6 +310,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLCipher.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SQLCipher.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyGif.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyGif.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TauEngine.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/android_path_provider.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/android_path_provider.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/disk_space.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/disk_space.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/file_picker.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/file_picker.framework",
@ -317,7 +318,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_local_notifications.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_local_notifications.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_olm.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_olm.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_secure_storage.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_secure_storage.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_sound.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/image_picker.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/image_picker.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/native_imaging.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/native_imaging.framework",

View File

@ -30,7 +30,7 @@ enum AudioPlayerStatus { NOT_DOWNLOADED, DOWNLOADING, DOWNLOADED }
class _AudioPlayerState extends State<AudioPlayer> { class _AudioPlayerState extends State<AudioPlayer> {
AudioPlayerStatus status = AudioPlayerStatus.NOT_DOWNLOADED; AudioPlayerStatus status = AudioPlayerStatus.NOT_DOWNLOADED;
FlutterSound flutterSound = FlutterSound(); FlutterSoundPlayer flutterSound = FlutterSoundPlayer();
StreamSubscription soundSubscription; StreamSubscription soundSubscription;
Uint8List audioFile; Uint8List audioFile;
@ -57,10 +57,12 @@ class _AudioPlayerState extends State<AudioPlayer> {
@override @override
void dispose() { void dispose() {
if (flutterSound.audioState == t_AUDIO_STATE.IS_PLAYING) { if (flutterSound.playerState == PlayerState.isPlaying) {
flutterSound.stopPlayer(); flutterSound.stopPlayer();
} }
soundSubscription?.cancel(); soundSubscription?.cancel();
flutterSound?.closeAudioSession();
flutterSound = null;
super.dispose(); super.dispose();
} }
@ -79,28 +81,25 @@ class _AudioPlayerState extends State<AudioPlayer> {
void _playAction() async { void _playAction() async {
if (AudioPlayer.currentId != widget.event.eventId) { if (AudioPlayer.currentId != widget.event.eventId) {
if (AudioPlayer.currentId != null) { if (AudioPlayer.currentId != null) {
if (flutterSound.audioState != t_AUDIO_STATE.IS_STOPPED) { if (flutterSound.playerState != PlayerState.isStopped) {
await flutterSound.stopPlayer(); await flutterSound.stopPlayer();
setState(() => null); setState(() => null);
} }
} }
AudioPlayer.currentId = widget.event.eventId; AudioPlayer.currentId = widget.event.eventId;
} }
switch (flutterSound.audioState) { switch (flutterSound.playerState) {
case t_AUDIO_STATE.IS_PLAYING: case PlayerState.isPlaying:
await flutterSound.pausePlayer(); await flutterSound.pausePlayer();
break; break;
case t_AUDIO_STATE.IS_PAUSED: case PlayerState.isPaused:
await flutterSound.resumePlayer(); await flutterSound.resumePlayer();
break; break;
case t_AUDIO_STATE.IS_RECORDING: case PlayerState.isStopped:
break; await flutterSound.startPlayer(
case t_AUDIO_STATE.IS_STOPPED: fromDataBuffer: audioFile,
await flutterSound.startPlayerFromBuffer(
audioFile,
codec: t_CODEC.CODEC_AAC,
); );
soundSubscription ??= flutterSound.onPlayerStateChanged.listen((e) { soundSubscription ??= flutterSound.onProgress.listen((disposition) {
if (AudioPlayer.currentId != widget.event.eventId) { if (AudioPlayer.currentId != widget.event.eventId) {
soundSubscription?.cancel()?.then((f) => soundSubscription = null); soundSubscription?.cancel()?.then((f) => soundSubscription = null);
setState(() { setState(() {
@ -108,16 +107,16 @@ class _AudioPlayerState extends State<AudioPlayer> {
statusText = '00:00'; statusText = '00:00';
}); });
AudioPlayer.currentId = null; AudioPlayer.currentId = null;
} else if (e != null) { } else if (disposition != null) {
var date = var date = DateTime.fromMillisecondsSinceEpoch(
DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt()); disposition.position.inMilliseconds.toInt());
var txt = DateFormat('mm:ss', 'en_US').format(date); var txt = DateFormat('mm:ss', 'en_US').format(date);
setState(() { setState(() {
maxPosition = e.duration; maxPosition = disposition.duration.inMilliseconds.toDouble();
currentPosition = e.currentPosition; currentPosition = disposition.position.inMilliseconds.toDouble();
statusText = txt; statusText = txt;
}); });
if (e.duration == e.currentPosition) { if (disposition.duration == disposition.position) {
soundSubscription soundSubscription
?.cancel() ?.cancel()
?.then((f) => soundSubscription = null); ?.then((f) => soundSubscription = null);
@ -151,7 +150,7 @@ class _AudioPlayerState extends State<AudioPlayer> {
? CircularProgressIndicator(strokeWidth: 2) ? CircularProgressIndicator(strokeWidth: 2)
: IconButton( : IconButton(
icon: Icon( icon: Icon(
flutterSound.audioState == t_AUDIO_STATE.IS_PLAYING flutterSound.playerState == PlayerState.isPlaying
? Icons.pause ? Icons.pause
: Icons.play_arrow, : Icons.play_arrow,
color: widget.color, color: widget.color,
@ -168,8 +167,8 @@ class _AudioPlayerState extends State<AudioPlayer> {
Expanded( Expanded(
child: Slider( child: Slider(
value: currentPosition, value: currentPosition,
onChanged: (double position) => onChanged: (double position) => flutterSound
flutterSound.seekToPlayer(position.toInt()), .seekToPlayer(Duration(milliseconds: position.toInt())),
max: status == AudioPlayerStatus.DOWNLOADED ? maxPosition : 0, max: status == AudioPlayerStatus.DOWNLOADED ? maxPosition : 0,
min: 0, min: 0,
), ),

View File

@ -6,16 +6,14 @@ import 'package:flutter_sound/flutter_sound.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
class RecordingDialog extends StatefulWidget { class RecordingDialog extends StatefulWidget {
final Function onFinished; const RecordingDialog({Key key}) : super(key: key);
const RecordingDialog({this.onFinished, Key key}) : super(key: key);
@override @override
_RecordingDialogState createState() => _RecordingDialogState(); _RecordingDialogState createState() => _RecordingDialogState();
} }
class _RecordingDialogState extends State<RecordingDialog> { class _RecordingDialogState extends State<RecordingDialog> {
FlutterSound flutterSound = FlutterSound(); FlutterSoundRecorder flutterSound = FlutterSoundRecorder();
String time = '00:00:00'; String time = '00:00:00';
StreamSubscription _recorderSubscription; StreamSubscription _recorderSubscription;
@ -24,12 +22,11 @@ class _RecordingDialogState extends State<RecordingDialog> {
void startRecording() async { void startRecording() async {
try { try {
await flutterSound.startRecorder( final recorder = await flutterSound.openAudioSession();
codec: t_CODEC.CODEC_AAC, await recorder.startRecorder();
); _recorderSubscription = flutterSound.onProgress.listen((disposition) {
_recorderSubscription = flutterSound.onRecorderStateChanged.listen((e) { var date = DateTime.fromMillisecondsSinceEpoch(
var date = disposition.duration.inMilliseconds.toInt());
DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
setState(() => time = DateFormat('mm:ss:SS', 'en_US').format(date)); setState(() => time = DateFormat('mm:ss:SS', 'en_US').format(date));
}); });
} catch (e) { } catch (e) {
@ -47,6 +44,8 @@ class _RecordingDialogState extends State<RecordingDialog> {
void dispose() { void dispose() {
if (flutterSound.isRecording) flutterSound.stopRecorder(); if (flutterSound.isRecording) flutterSound.stopRecorder();
_recorderSubscription?.cancel(); _recorderSubscription?.cancel();
flutterSound?.closeAudioSession();
flutterSound = null;
super.dispose(); super.dispose();
} }
@ -83,7 +82,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
color: Theme.of(context).textTheme.bodyText2.color.withAlpha(150), color: Theme.of(context).textTheme.bodyText2.color.withAlpha(150),
), ),
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop<String>(null),
), ),
FlatButton( FlatButton(
child: Row( child: Row(
@ -95,11 +94,8 @@ class _RecordingDialogState extends State<RecordingDialog> {
), ),
onPressed: () async { onPressed: () async {
await _recorderSubscription?.cancel(); await _recorderSubscription?.cancel();
final result = await flutterSound.stopRecorder(); await flutterSound.stopRecorder();
if (widget.onFinished != null) { Navigator.of(context).pop<String>(flutterSound.savedUri);
widget.onFinished(result);
}
Navigator.of(context).pop();
}, },
), ),
], ],

View File

@ -266,14 +266,12 @@ class _ChatState extends State<_Chat> {
} }
void voiceMessageAction(BuildContext context) async { void voiceMessageAction(BuildContext context) async {
String result; final filePath = await showDialog<String>(
await showDialog( context: context,
context: context, builder: (context) => RecordingDialog(),
builder: (context) => RecordingDialog( );
onFinished: (r) => result = r, if (filePath == null) return;
)); final audioFile = File(filePath);
if (result == null) return;
final audioFile = File(result);
// as we already explicitly say send in the recording dialog, // as we already explicitly say send in the recording dialog,
// we do not need the send file dialog anymore. We can just send this straight away. // we do not need the send file dialog anymore. We can just send this straight away.
await SimpleDialogs(context).tryRequestWithLoadingDialog( await SimpleDialogs(context).tryRequestWithLoadingDialog(

View File

@ -404,7 +404,28 @@ packages:
name: flutter_sound name: flutter_sound
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "6.4.2+1"
flutter_sound_platform_interface:
dependency: transitive
description:
name: flutter_sound_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "6.4.2+1"
flutter_sound_web:
dependency: transitive
description:
name: flutter_sound_web
url: "https://pub.dartlang.org"
source: hosted
version: "6.4.2+1"
flutter_spinkit:
dependency: transitive
description:
name: flutter_spinkit
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.2+1"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -534,6 +555,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.3+6" version: "3.0.3+6"
logger:
dependency: transitive
description:
name: logger
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.0+2"
logging: logging:
dependency: transitive dependency: transitive
description: description:
@ -606,6 +634,13 @@ packages:
url: "https://gitlab.com/famedly/libraries/native_imaging.git" url: "https://gitlab.com/famedly/libraries/native_imaging.git"
source: git source: git
version: "0.0.1" version: "0.0.1"
nested:
dependency: transitive
description:
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
node_interop: node_interop:
dependency: transitive dependency: transitive
description: description:
@ -781,6 +816,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.13" version: "3.0.13"
provider:
dependency: transitive
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.2+2"
pub_semver: pub_semver:
dependency: transitive dependency: transitive
description: description:
@ -802,6 +844,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
recase:
dependency: transitive
description:
name: recase
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
receive_sharing_intent: receive_sharing_intent:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -45,7 +45,7 @@ dependencies:
receive_sharing_intent: ^1.4.2 receive_sharing_intent: ^1.4.2
flutter_slidable: ^0.5.7 flutter_slidable: ^0.5.7
photo_view: ^0.10.2 photo_view: ^0.10.2
flutter_sound: 2.1.1 flutter_sound: ^6.4.2+1
open_file: ^3.0.3 open_file: ^3.0.3
mime_type: ^0.3.2 mime_type: ^0.3.2
flushbar: ^1.10.4 flushbar: ^1.10.4