[ad_1]
I am utilizing flutter-sound to document (after which play again) some audio in my flutter app. Nonetheless, I’ve run up in opposition to an fascinating downside: On the iOS emulator it really works, however on the precise iOS gadget I get an obscure error. Each are operating on the identical model of iOS (15.4).
Right here is the code for beginning and stopping the recording/playback, it is easy sufficient:
Future<void> startRecording(GlobalState curState) async {
setState(() {
recording = true;
});
curState.startRecording();
Listing listing = Listing(pathToAudio);
if (filePathText.isNotEmpty && File(filePathText).existsSync()) {
File(filePathText).deleteSync();
}
if (!listing.existsSync()) {
listing.createSync();
}
await _recordingSession.startRecorder(
toFile: (filePathName()),
codec: (Platform.isIOS ? Codec.pcm16WAV : Codec.aacMP4),
audioSource: AudioSource.microphone,
);
}
Future<void> stopRecording(GlobalState curState) async {
setState(() {
recording = false;
});
String? fileURL = await _recordingSession.stopRecorder();
print("the file is recorded!!!");
print("FILEPATH:");
print(fileURL);
curState.stopRecording();
if (fileURL != null) {
filePathText = fileURL;
if (widget.widgetControlInfo.onChanged != null) {
FileAnswer tempA = FileAnswer.fromBasicQuestion(widget.currentQuestion);
tempA.filePath = fileURL;
tempA.filetype = FileType.recording;
if (widget.widgetControlInfo.onChanged != null) {
widget.widgetControlInfo.onChanged!(tempA);
}
}
} else {
print('sumn went rong wit da recording');
}
}
String filePathName() =>
pathToAudio +
DateTime.now().month.toString() +
DateTime.now().day.toString() +
DateTime.now().hour.toString() +
DateTime.now().minute.toString() +
DateTime.now().second.toString() +
(Platform.isIOS ? ".wav" : ".m4a");
Future<void> playControl() async {
if (enjoying) {
await stopPlaying();
} else {
await startPlaying();
}
}
Future<void> startPlaying() async {
setState(() {
enjoying = true;
});
if (filePathText.isEmpty) {
return;
} else {
if (File(filePathText).existsSync()) {
print("the file existssss!!!");
print("FILEPATH:");
print(filePathText);
}
await _playingSession.startPlayer(
fromURI: filePathText,
codec: (Platform.isIOS ? Codec.pcm16WAV : Codec.aacMP4),
whenFinished: () {
print("its over");
stopPlaying();
});
}
return;
}
Future<void> stopPlaying() async {
setState(() {
enjoying = false;
});
await _playingSession.stopPlayer();
}
void _initializer() async {
if (Platform.isIOS) {
var listing = await getTemporaryDirectory();
print("TIS IOS");
pathToAudio = listing.path + "https://stackoverflow.com/";
} else {
pathToAudio = '/sdcard/Obtain/m-Path/';
}
_recordingSession = new FlutterSoundRecorder(logLevel: Stage.debug);
_playingSession = new FlutterSoundPlayer(logLevel: Stage.debug);
await _recordingSession.openRecorder();
await _playingSession.openPlayer();
await _recordingSession
.setSubscriptionDuration(Length(milliseconds: 10))
.then((worth) => null);
_recorderSubscription = _recordingSession.onProgress!.pay attention((e) {
setState(() {
_timerText = e.period.toString().substring(0, 10);
});
});
await _playingSession.setSubscriptionDuration(Length(milliseconds: 10));
_playerSubscription = _playingSession.onProgress!.pay attention((e) {
setState(() {
_timerText = e.place.toString().substring(0, 10);
});
});
await Permission.microphone.request();
await Permission.storage.request();
await Permission.manageExternalStorage.request();
}
This is what the UI portion appears to be like like. On the iOS emulator, after I press the recording button, the timer begins incrementing, and after I press it once more, I can press the play button to pay attention what I simply recorded. On the gadget, after I press the button, the timer does not increment however stays at zero, and when I attempt to play the audio, I get the next error:
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: PlatformException(Audio Participant, startPlayer failure, null, null)
#0 StandardMethodCodec.decodeEnvelope (bundle:flutter/src/providers/message_codecs.dart:607:7)
#1 MethodChannel._invokeMethod (bundle:flutter/src/providers/platform_channel.dart:177:18)
<asynchronous suspension>
#2 MethodChannelFlutterSoundPlayer.invokeMethod (bundle:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:157:12)
<asynchronous suspension>
#3 FlutterSoundPlayer._startPlayer (bundle:flutter_sound/public/flutter_sound_player.dart:819:19)
<asynchronous suspension>
#4 FlutterSoundPlayer.startPlayer.<nameless closure> (bundle:flutter_sound/public/flutter_sound_player.dart:759:11)
<asynchronous suspension>
#5 BasicLock.synchronized (bundle:synchronized/src/basic_lock.dart:33:16)
<asynchronous suspension>
#6 FlutterSoundPlayer.startPlayer (bundle:flutter_sound/public/flutter_sound_player.dart:758:5)
<asynchronous suspension>
#7 _RecordingQuestionWidgetS.startPlaying (bundle:flutter_app2/interactions/widgets/questionWidgets/RecordingQuestionWidget.dart:216:7)
<asynchronous suspension>
#8 _RecordingQuestionWidgetS.playControl (bundle:flutter_app2/interactions/widgets/questionWidgets/RecordingQuestionWidget.dart:200:7)
<asynchronous suspension>
I requested the flutter-sound writer on github already, but it surely appears he does not actually know what’s fallacious both, and the truth that it really works on the simulator however not on the gadget makes me assume the issue is perhaps bigger than simply some defective code.
A special a part of the identical app already saves and reveals saved photos from the identical listing so I do not assume it is a permission concern.
[ad_2]
