flutter_sound 8.4.2 startPlayer() exception - flutter

await _audioPlayer!.startPlayer(
fromURI: 'https://URL/TestFiles/sssssssss.acc',
codec: Codec.aacADTS,
);
} catch (e) {
print(e);
}
the exception is platform exceptio error unknown startplayer() error,null .
in the debug console I got these
FlutterSoundPlayer.log (package:flutter_sound/public/flutter_sound_player.dart:500:13
MethodChannelFlutterSoundPlayer.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:161:19
I am using real android device
flutter doctor returns everything is good
this remote file works well in angular client

It's played Now I was missing that the file extension is aac not acc
so it should be
await _audioPlayer!.startPlayer(
fromURI: 'https://URL/TestFiles/sssssssss.aac',
);
} catch (e) {
print(e);
}

to play audios i use this library
audioplayers: ^0.19.1
declare this variable to access audio
String audioCorrect = "audio/access_granted.mp3";
String audioInCorrect = "audio/access_denied.mp3";
method for init player
void initPlayer() {
advancedPlayer = new AudioPlayer();
audioCache = new AudioCache(fixedPlayer: advancedPlayer);
}
call initPlayer in initState method
play the audio this way
audioCache.play(audioCorrect);

Related

Flutter recording feature working on emulator but not on actual device

I am developing an app that can record and play sound. Everything works fine on my emulator. But when I try to run the app on my device, it always gives me this error:
java.lang.NullPointerException: Attempt to invoke virtual method 'long android.os.storage.StorageVolume.getMaxFileSize()' on a null object reference
The way I implement the recording feature is to record the audio to a temporary file, and playback from it. This is the corresponding code, I am using flutter sound by the way:
String pathToSaveAudio = '';
class SoundRecorder {
FlutterSoundRecorder? _audioRecorder;
bool _isRecordingInitialised = false;
bool get isRecording => _audioRecorder!.isRecording;
// getters
bool getInitState() {
return _isRecordingInitialised;
}
FlutterSoundRecorder? getRecorder() {
return _audioRecorder;
}
/// init recorder
Future init() async {
_audioRecorder = FlutterSoundRecorder();
final status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
throw RecordingPermissionException('Microphone permission denied');
}
await _audioRecorder!.openRecorder();
_isRecordingInitialised = true;
var tempDir = await getTemporaryDirectory();
pathToSaveAudio = '${tempDir.path}/audio.mp4';
}
/// dipose recorder
void dispose() {
_audioRecorder!.closeRecorder();
_audioRecorder = null;
_isRecordingInitialised = false;
}
/// start record
Future _record() async {
assert(_isRecordingInitialised);
await _audioRecorder!
.startRecorder(toFile: pathToSaveAudio, codec: Codec.aacMP4);
}
/// stop record
Future _stop() async {
if (!_isRecordingInitialised) return;
await _audioRecorder!.stopRecorder();
}
I think what I'm doing is record the sound and put it in the file in that temp directory. But appearently the app want to acces the file before I even start recording. At this point, I don't know what to do, please help me.

Flutter webrtc screen sharing

I have a flutter project (iOS, Android) that uses WebRTC. I need to send video from camera (working correctly) and screen capture by WebRTC. How to share the screen on WebRTC with the flutter_webrtc package?
You can use the flutter_webrtc plugin and do like this method ( use getDisplayMedia method in webRTC to get display ) :
class ScreenSharing {
MediaStream? _localStream;
final RTCVideoRenderer _localRenderer = RTCVideoRenderer();
Future<void> _makeScreenSharing() async {
final mediaConstraints = <String, dynamic>{'audio': true, 'video': true};
try {
var stream = await navigator.mediaDevices.getDisplayMedia(mediaConstraints);
_localStream = stream;
_localRenderer.srcObject = _localStream;
} catch (e) {
print(e.toString());
}
}
}

flutter sounds unable to play audio file

I am using flutter_sounds package to play audio file.
My audio file exists and is valid file.
For some unknown reason below code is not working and unable to play the audio.
FlutterSoundPlayer _mPlayer = FlutterSoundPlayer();
try {
var t = await _mPlayer.openAudioSession();
print('after open');
print('_mPlayerIsInited');
setState(() async {
_isPlayerToucher = true;
_mPlayerIsInited = true;
_mPlayerisPaused = false;
});
} catch (e) {
print('ERROR');
print(e.toString());
}
await _mPlayer.startPlayer(
fromURI: widget.content,
whenFinished: () async {
await _mPlayer.stopPlayer();
_mPlayer.closeAudioSession();
setState(() {
_mPlayerIsInited = false;
});
});
I am unable to see the print 'after open'
i see below in console.
I/flutter ( 7834): FS:---> openAudioSession
I recommend you to use another package audioplayers
AudioCache _audioCache;
_audioCache = AudioCache(
prefix: "audio/",
fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP));
_audioCache.play('open-up.mp3');

Does face ID support for android in Flutter?

i am trying to implement faceID for android in flutter. My android phone has face unlock feature but unable to detect while running my flutter app in phone. i am using below code :
Future<void> _getListOfBiometricTypes() async {
List<BiometricType> listofBiometrics;
try {
listofBiometrics = await _localAuthentication.getAvailableBiometrics();
} on PlatformException catch (e) {
print(e);
}
if (!mounted) return;
setState(() {
_availableBiometricTypes = listofBiometrics;
print(_availableBiometricTypes.length);
print(_availableBiometricTypes.toString());
});
}
only finger print detected. Why not showing face ID detection?

Detecting corrupt videos in Flutter Video Player

If I load a corrupt video into flutter video player using the following code the intialise future never completes nor is an error thrown... it just seems to hang.
videoController = VideoPlayerController.file(f)
..initialize().then((_) async {
setState(() {
});
}).catchError((error){
print(error);
}).whenComplete((){
print("ITS GONE IN THE whenComplete");
});
I have tried using the addListener to check if it has error but this also never is true.
e.g.
if (videoController.value.hasError) {
print(videoController.value.errorDescription);
const x = 1;
}
Is there anyway to tell whether a video has failed to load without using a timeout?
---- EDIT
Also I cannot use FFmpeg to test if the video is corrupt before using it.
Try to catch the error like this
try {
videoController = VideoPlayerController.file(f);
await videoController.initialize();
setState(() {});
} catch (e) {
print(error);
}