Can controller.StartImageStream() be restarted after controller.stopImageStream or is there a way to pause - flutter

Hope someone can help me. I am a blind guy and am creating a app to recognise ZA banknotes. I find my results is better after controller.stopImageStream(); rather than running the image stream continuesly. How can I restart controller.startImageStream() after the stop? or is there a way to pause the imageStream rather then stopping it. Thank you
setState(() {});
controller.startImageStream((CameraImage img) {
controller.stopImageStream();
if (!isDetecting) {
isDetecting = true;
int startTime = new DateTime.now().millisecondsSinceEpoch;
Tflite.runModelOnFrame(

Related

Cant get video progress time in Flutter better player

I am building a video player app in flutter with better video player. All things are working fine with better player except that i cant get the video player progress(time of how much the video has been played) in better player and i also want to get the total time of the video too. Does anyone has any idea of how to get the video progress with it.. it will be helpfull with an example.
You can set the listener in BetterPlayerConfiguration, than you can get video duration and progress using event.parameters. Please, see the example below:
BetterPlayerConfiguration get _betterPlayerConfiguration => BetterPlayerConfiguration(
eventListener: _onPlayerEvent,
);
void _onPlayerEvent(BetterPlayerEvent event) {
if (_checkIfCanProcessPlayerEvent(event)) {
Duration progress = event.parameters!['progress'];
Duration duration = event.parameters!['duration'];
}
}
bool _checkIfCanProcessPlayerEvent(BetterPlayerEvent event) {
return
event.betterPlayerEventType == BetterPlayerEventType.progress &&
event.parameters != null &&
event.parameters!['progress'] != null &&
event.parameters!['duration'] != null;
}
you can get control of all events in better player after you create betterplayercontroller like this
_betterPlayerController!.addEventsListener((event) {
if (event.betterPlayerEventType == BetterPlayerEventType.finished) {
LessonRepo.completeVideo(lessonID: lessonID);
}
});
Duration myProgress;
_betterPlayerController.addEventsListener((event) => {
if (event.betterPlayerEventType == BetterPlayerEventType.progress) {
myProgress = event.parameters['progress']
},
}

How to improve scanning qr codes?

I am creating some kind of streaming app.
I have open camera and I implemented scanning qr codes in background using https://pub.dev/packages/google_ml_kit
Here is my code for that:
var stream = await navigator.mediaDevices
.getUserMedia({'video': true, 'audio': true});
setState(() {
_localRenderer.srcObject = stream;
});
streamTrack = stream.getVideoTracks().first;
await Future.delayed(Duration(seconds: 2));
_getSnapshotTimer = Timer.periodic(Duration(seconds: 1), (timer) async { // skanowanie kodów QR
final frame = await streamTrack.captureFrame();
File file = await File('${_tempDir.path}/image.png').create();
file.writeAsBytesSync(frame.asUint8List());
final _qrCodes =
await _qrCodeScanner.processImage(InputImage.fromFile(file));
My problem is because of that video from camera is lagging every second. There is like a little freeze.
There is some option to improve this? To make video from camera smooth all time?
Running the QR code scanner while your device is running a dev version and tethered to your computer capturing debug data can slow it down. I have an app with a QR scanner that works great in production but shows the same lagging symptoms in the development environment. I can't comment specifically on your project, as it seems like you're doing more than just capturing a QR code, but there is definitely a lag effect from running it in the development environment.

Flutter Audioplayers delay

I'm coding a small game with the Flutter Framework.
I'm using audioplayers for the Sounds.
It works fine like this, when calling it for example 2 times a second.
But whenn I call it more than 5 times and again in the next second at some point the sound has like a delay and then after a second or so all the sounds play at once :) That sounds weired.
I also tested the audioplayers example from github on my iphone. Repeating the sounds in low frequency is ok, but when I repeat clicking the button as fast as possible at some point it gets some delay and the same thing is happening.
Is there some way to stop the previous Sound before and then playing the next one or isnt this possible?
Or is there some other Idea how to deal with the sounds?
This is how I use it:
AudioCache upgradeSound = new AudioCache();
void playUpgradeSound() {
_playUpgradeSound(upgradeSound);
}
void _playUpgradeSound(AudioCache ac) async{
await ac.play('audio/upgr.mp3');
}
Thank you very much in advance
I solve similar problem by having singleton class, and after first play I can get the state, and I can stop previous play.
class Audio {
static final playerCache = AudioCache();
static AudioPlayer audioPlayer;
static void play(String audioName) async {
audioPlayer = await playerCache.play('$audioName.mp3');
}
static void stop() {
audioPlayer.stop();
}
}
...
child: IconButton(
onPressed: () {
try {
if (Audio.audioPlayer.state ==
AudioPlayerState.PLAYING) {
Audio.stop();
} else {
Audio.play('bid');
}
} catch (e) {
Audio.play('bid');
}
},
...
There is a line of code in its own documentation.
To use the low latency API, better for gaming sounds, use:
AudioPlayer audioPlayer = AudioPlayer(mode: PlayerMode.LOW_LATENCY);
In this mode the backend won't fire any duration or position updates. Also, it is not possible to use the seek method to set the audio a specific position. This mode is also not available on web.
I hope it is useful.

Flutter - Stop audio playback from recorded video in the background

Essentially the app is like snapchat. I take pics and reset back to camera mode, the issue comes when I record video and reset, it goes back to camera mode but the audio form the video keeps playing in the background. The functions are somwhat exactly like the camera doc, with a few addition to reset the camera.
I added this:
_reset() {
if (mounted)
setState(() {
if (this._didCapture) {
this._didCapture = false;
this._isRecording = false;
this._isPosting = false;
this._file = File('');
this._fileType = null;
this._captions.clear();
this._textEditingControllers.clear();
this._videoController = null;
this._videoPlayerListener = null;
}
});
}
It works just fine but the audio in the background is still on. Also wondering if the video/picture is saved on the phone, which I don't want to...
i had been looking for a similar answer, but i didn´t find it. You could try to stop it adding this to your function:
this._controller.setVolume(0.0);
that´s what i did in my app

Missing Field Exception Unity3d Script

When I compile my game in debug mode in Unity3D it instantly pauses a quick glance at the console reveals the following error:
MissingFieldException: UnityEngine.Light.Enable
Here is the script it is very simply meant to make the point light flicker when the randomiser is below 0.7.
var FlashingLight : Light;
FlashingLight.enabled = false;
function FixedUpdate (){
var RandomNumber = Random.value;
if(RandomNumber<=.7){
FlashingLight.enable = true;
}
else FlashingLight.enabled=false;
}
Any help would be appreciated, thanks.
The field is called enabled, not enable.