I want to turn on and turn off camera on the same screen in flutter app during particular time intervals - flutter

Thanks in Advance
Currently my app uses camera to take video input and process each frames . The app also works in background for hours. So to avoid heating issues I need to turn the camera off and on it later.
The camera is turned off when I use
_camera.dispose()
but its not turned on after disposing when I use
_camera.initialize()
CameraDescription description = await getCamera(_direction);
ImageRotation rotation = rotationIntToImageRotation(
description.sensorOrientation,
);
_camera =CameraController(description, ResolutionPreset.low, enableAudio: false);
await _camera.initialize();
_camera.startImageStream((CameraImage image) {
_baseStopwatch.start();
if (_baseStopwatch.elapsed.inSeconds > 5) {
_camera.stopImageStream(); }
if (_baseStopwatch.elapsed.inSeconds > 10){
// need to restart the camera streaming!!
}}

Related

How to set audio handler with carousel slider in flutter?

Currently i am working on music app and according to my ui i have to manage audio player with carousel slider.The without carousel slider it is working fine but with carousel slider when click on the shuffle or when onPageChanged called, i used the skipToQueueItem for play particular song with audio player, that time suddenly audioHandler.mediaItem listen continuously called and in every 1 second changed song and slider images because of skipToQueueItem line.I used just audio and audio service package.For privacy i am not sharing the code.But for update carousel slider with audio i used below code.
audioHandler.queue.listen((playlist) async {
if (playlist.isEmpty) {
mediaItemsListNotifier.value = [];
} else {
///Update media items notifier list value
mediaItemsListNotifier.value = playlist;
await audioHandler.updateQueue(playlist);
}
});
audioHandler.mediaItem.listen((mediaItem) async {
int index = audioHandler.queue.value.indexOf(mediaItem!);
currentSliderIndex.value = index >= 0 ? index : 0;
///Main issue using this line
await audioHandle.skipToQueueItem(currentSliderIndex.value);
carouselController.jumpToPage(currentSliderIndex.value);
}

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 - 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

How to create a dynamic gradient background 2d in unity

I am new to unity and for my project I need a gradient background which changes after a certain amount of time. I searched a lot and not able to get it . Can anyone please explain me step by step with respective coding and procedures. Reference to this type of background is the mobile game stack
I think you can make it normaly by create 2 background. After a certain amount of time just fade old background and enable new background. Code example:
void ChangeBackground()
{
newImage.gameObject.SetActive(true);
StartCoroutine(FadeImage(0.1f));
}
IEnumerator FadeImage(float speedStep)
{
Color newColor = oldImage.color;
while (newColor.a > 0)
{
newColor.a -= speedStep;
oldImage.color = newColor;
yield return null;
}
oldImage.gameObject.SetActive(false);
}

How to capture continious image in Android

I'm trying to develop an android application which should take continuous images just like native camera in continuous shooting mode for 10 to 20 seconds.
I followed the sample program from the site
http://marakana.com/forums/android/examples/39.html
Now , i want to enhance this code to take continuous images (for 10 to 20 seconds) ,
first i tried to take 10 pics by using a for loop ,
i just put the takePicture() function in the loop , but that'S not working .
do i need to use threadS .
IF YES , THEN which part should i put in thread , the image capturing or image saving to
sd card
If any body having some sample code for taking continuous images , pls share.
Just put a counter in the jpegCallBack function, that decrements and calls your takePicture() again until the wished number of pictures is reached.
int pictureCounter = 10;
PictureCallback jpegCallback = new PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
// save your picture
if(--pictureCounter>=0) {
takePicture();
} else {
pictureCounter = 10; // reset the counter
}
}
I know it is very late to reply, but I just came across this question and thought it would be helpful for future visitors.
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
//Save Picture here
preview.camera.stopPreview();
// if condition
preview.camera.startPreview();
// end if condition
}
};