flutter camera: Error clearing streaming request: Function not implemented - flutter

I am working on an app in flutter that uses the camera.
I have followed the basic flutter tutorial
https://flutter.dev/docs/cookbook/plugins/picture-using-camera
However, when I am on a screen using the CameraPreview widget, and I navigate to another app that uses the camera, like snapchat, I see the following error when opening snapchat (the error comes from my app), has anyone else seen this before?
Returning to my app shows the camera in a frozen/paused state.
I/CameraManagerGlobal(30470): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_IDLE for client com.my.cliet API Level 2
I/CameraManagerGlobal(30470): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client com.my.cliet API Level 2
E/CameraCaptureSession(30470): Session 0: Exception while stopping repeating:
E/CameraCaptureSession(30470): android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): cancelRequest:547: Camera 0: Error clearing streaming request: Function not implemented (-38)
E/CameraCaptureSession(30470): at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:1340)
E/CameraCaptureSession(30470): at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRequest(ICameraDeviceUserWrapper.java:99)
E/CameraCaptureSession(30470): at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1259)
E/CameraCaptureSession(30470): at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:578)
E/CameraCaptureSession(30470): at android.hardware.camera2.impl.CameraCaptureSessionImpl$2.onDisconnected(CameraCaptureSessionImpl.java:789)
E/CameraCaptureSession(30470): at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:245)
E/CameraCaptureSession(30470): at android.os.Handler.handleCallback(Handler.java:938)
E/CameraCaptureSession(30470): at android.os.Handler.dispatchMessage(Handler.java:99)
E/CameraCaptureSession(30470): at android.os.Looper.loop(Looper.java:246)
E/CameraCaptureSession(30470): at android.app.ActivityThread.main(ActivityThread.java:8506)
E/CameraCaptureSession(30470): at java.lang.reflect.Method.invoke(Native Method)
E/CameraCaptureSession(30470): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
E/CameraCaptureSession(30470): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
E/CameraCaptureSession(30470): Caused by: android.os.ServiceSpecificException: cancelRequest:547: Camera 0: Error clearing streaming request: Function not implemented (-38) (code 10)
E/CameraCaptureSession(30470): at android.os.Parcel.createExceptionOrNull(Parcel.java:2399)
E/CameraCaptureSession(30470): at android.os.Parcel.createException(Parcel.java:2369)
E/CameraCaptureSession(30470): at android.os.Parcel.readException(Parcel.java:2352)
E/CameraCaptureSession(30470): at android.os.Parcel.readException(Parcel.java:2294)
E/CameraCaptureSession(30470): at android.hardware.camera2.ICameraDeviceUser$Stub$Proxy.cancelRequest(ICameraDeviceUser.java:750)
E/CameraCaptureSession(30470): at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRequest(ICameraDeviceUserWrapper.java:97)
E/CameraCaptureSession(30470): ... 11 more

So I have resolved the issue by adding the following which aren't included in the link that I posted.
in the initState() method I had to manually add the observer
WidgetsBinding.instance!.addObserver(this);
I had to define/modify the didChangeAppLifecycleState(...) function as follows
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
final CameraController? cameraController = _controller;
// App state changed before we got the chance to initialize.
if (cameraController == null || !cameraController.value.isInitialized) {
return;
}
if (state == AppLifecycleState.inactive) {
cameraController.dispose();
} else if (state == AppLifecycleState.resumed) {
this._controller = CameraController(
widget.camera,
ResolutionPreset.medium,
);
if (mounted) {
setState(() {
this._initializeControllerFuture = this._controller.initialize();
});
}
}
}

Related

Flutter crashes when using AudioPlayers and Future.wait to play a list of sound effects simultaneously

I'd like to create a list of List<Future<void>> that represent executions of sound effects.
I therefore iterate through a list of event types/formats (ie. "sword") and map each to a sound effect play execution.
I wrap these Futures in a Future.delayed for each with a random number of milliseconds from 30 to 100 just to have a little random occurance of when the sound effects are played in order (to add a pause between two sound effects).
The list of those sound effect Futures is then called by Future.wait where I expected the list to be resolved and the Future.delay might take effect.
This is my code
_playActionEventSounds() async {
if (widget.log.isNotEmpty) {
final lastRound = widget.log.map((e) => e.round).reduce(max);
final lastActionEvents = widget.log.where((actionEvent) => actionEvent.round == lastRound);
final List<Future<void>> eventSounds = lastActionEvents.map((actionEvent) async {
if (actionEvent.format == "sword") {
return Future.delayed(Duration(milliseconds: next(30, 100)), () => _soundPlayer.punch());
}
if (actionEvent.format == "damage") {
return Future.delayed(Duration(milliseconds: next(30, 100)), () => _soundPlayer.pain());
}
return Future.value(null);
}).toList();
await Future.wait(eventSounds);
}
}
SoundPlayer class:
import 'package:audioplayers/audioplayers.dart';
class SoundPlayer {
Future<void> punch() async {
final player = AudioPlayer();
player.setReleaseMode(ReleaseMode.stop);
return await player.play(AssetSource("sounds/punch.wav"));
}
Future<void> pain() async {
final player = AudioPlayer();
player.setReleaseMode(ReleaseMode.stop);
return await player.play(AssetSource("sounds/pain.wav"));
}
}
I now can run the process multiple times. I do hear the sounds appear as expected. But after the 4th execution the app crashes.
This is the error:
I/flutter (28346): Unexpected platform error: MediaPlayer error with what:MEDIA_ERROR_UNKNOWN {what:1} extra:MEDIA_ERROR_UNKNOWN {extra:-19}
E/MediaPlayerNative(28346): pause called in state 0, mPlayer(0xb400007a92646810)
E/MediaPlayerNative(28346): error (-38, 0)
E/MediaPlayerNative(28346): Attempt to call getDuration in wrong state: mPlayer=0xb400007a92646810, mCurrentState=0
E/MediaPlayerNative(28346): error (-38, 0)
E/MediaPlayerNative(28346): stop called in state 0, mPlayer(0xb400007a92646810)
E/MediaPlayerNative(28346): error (-38, 0)
E/MediaPlayerNative(28346): prepareAsync called in state 0, mPlayer(0xb400007a92646810)
D/AndroidRuntime(28346): Shutting down VM
E/AndroidRuntime(28346): FATAL EXCEPTION: main
E/AndroidRuntime(28346): Process: com.example.app, PID: 28346
E/AndroidRuntime(28346): java.lang.IllegalStateException
E/AndroidRuntime(28346): at android.media.MediaPlayer._prepare(Native Method)
E/AndroidRuntime(28346): at android.media.MediaPlayer.prepare(MediaPlayer.java:1313)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.MediaPlayerPlayer.prepare(MediaPlayerPlayer.kt:89)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.WrappedPlayer.stop(WrappedPlayer.kt:185)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.WrappedPlayer.onCompletion(WrappedPlayer.kt:248)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.MediaPlayerPlayer.createMediaPlayer$lambda-5$lambda-1(MediaPlayerPlayer.kt:17)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.MediaPlayerPlayer.$r8$lambda$3fK1i48Yert5dbg2Q8ZiB5tiKHg(Unknown Source:0)
E/AndroidRuntime(28346): at xyz.luan.audioplayers.player.MediaPlayerPlayer$$ExternalSyntheticLambda1.onCompletion(Unknown Source:2)
E/AndroidRuntime(28346): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:3559)
E/AndroidRuntime(28346): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(28346): at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(28346): at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(28346): at android.app.ActivityThread.main(ActivityThread.java:7842)
E/AndroidRuntime(28346): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(28346): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(28346): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
I/Process (28346): Sending signal. PID: 28346 SIG: 9
Lost connection to device.
I guess I somewhat messed up the resource management due the repeated execution. Therefore I guess the error lies somewhat in the API usage of audioplayers.dart?
I had to change the ReleaseMode to release. What I did was using stop that kept the resources in memory I guess and therefore cluttered the memory?

Flutter: Camera disconnect exception when other camera apps are opened

I'm currently using the flutter camera package to record and save videos, but I've noticed that the camera preview runs into an exception when the device's camera is opened on another app or when face unlock is used on the lock screen.
I've tried using didChangeAppLifecycleState to possibly fetch or reinitialize the camera, but there's no success yet.
await model.fetchCameras();
if (model.cameras.isNotEmpty) {
await model.onNewCameraSelected(model.cameras[model.cameraIndex], true);
}
}
This issue is currently opened here and here, but haven't been resolved.
I get this exception when the device's camera is opened in another app. I tried disposing the camera and reinitializing it in the sample code above, but it doesn't work.
E/CameraCaptureSession(31468): android.hardware.camera2.CameraAccessException: CAMERA_DISCONNECTED (2): cancelRequest:458: Camera device no longer alive
E/CameraCaptureSession(31468): at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:814)
E/CameraCaptureSession(31468): at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRequest(ICameraDeviceUserWrapper.java:95)
E/CameraCaptureSession(31468): at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1134)
E/CameraCaptureSession(31468): at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:526)
E/CameraCaptureSession(31468): at android.hardware.camera2.impl.CameraCaptureSessionImpl$2.onDisconnected(CameraCaptureSessionImpl.java:737)
E/CameraCaptureSession(31468): at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:242)
E/CameraCaptureSession(31468): at android.os.Handler.handleCallback(Handler.java:873)
E/CameraCaptureSession(31468): at android.os.Handler.dispatchMessage(Handler.java:99)
E/CameraCaptureSession(31468): at android.os.Looper.loop(Looper.java:214)
E/CameraCaptureSession(31468): at android.app.ActivityThread.main(ActivityThread.java:6981)
E/CameraCaptureSession(31468): at java.lang.reflect.Method.invoke(Native Method)
E/CameraCaptureSession(31468): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/CameraCaptureSession(31468): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
E/CameraCaptureSession(31468): Caused by: android.os.ServiceSpecificException: cancelRequest:458: Camera device no longer alive (code 4)
E/CameraCaptureSession(31468): at android.os.Parcel.createException(Parcel.java:1980)
E/CameraCaptureSession(31468): at android.os.Parcel.readException(Parcel.java:1934)
E/CameraCaptureSession(31468): at android.os.Parcel.readException(Parcel.java:1884)
E/CameraCaptureSession(31468): at android.hardware.camera2.ICameraDeviceUser$Stub$Proxy.cancelRequest(ICameraDeviceUser.java:402)
E/CameraCaptureSession(31468): at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRe
Any Ideas, on how to force the camera package to reinitialize?
On resume re initialise Camera
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
_controller != null
? _initializeControllerFuture = _controller.initialize()
: null; //on pause camera is disposed, so we need to call again "issue is only for android"
}
}
checkout https://medium.com/#navinkumar0118/take-a-picture-using-flutter-camera-a9c11d282632

Sending email with attachments via flutter_email_sender is not working on Android

I'm trying to send an email with a pdf attachment using flutter_email_sender, it works fine on iOS but throws Failed to find configured root error on Android. Below is the code.
Future<void> _downloadFile(String url, String filename) async {
var request = await httpClient.getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$filename');
await file.writeAsBytes(bytes);
setState(() {
_file = file;
});
}
final Email email = Email(
body: 'Email body',
subject: 'Email subject',
recipients: ['email#gmail.com'],
attachmentPath: _file.path,
);
await FlutterEmailSender.send(email);
and the stack trace:
E/MethodChannel#flutter_email_sender: Failed to handle method call
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.xxx.xx/app_flutter/account_opening.pdf at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:739)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418)
at com.sidlatau.flutteremailsender.FlutterEmailSenderPlugin.sendEmail(FlutterEmailSenderPlugin.kt:95)
at com.sidlatau.flutteremailsender.FlutterEmailSenderPlugin.onMethodCall(FlutterEmailSenderPlugin.kt:38)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:160)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-09-11 13:44:42.484 26003-26003/com.xxx.xx W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy#98fb11f
2019-09-11 13:44:42.505 26003-26003/com.xxx.xx D/AndroidRuntime: Shutting down VM
2019-09-11 13:44:42.512 26003-26003/com.xxx.xx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.xx, PID: 26003
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xx/com.kiwi.fluttercrashlytics.CrashActivity}: com.kiwi.fluttercrashlytics.FlutterException: PlatformException(error, Failed to find configured root that contains /data/data/com.xxx.xx/app_flutter/account_opening.pdf, null)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: com.kiwi.fluttercrashlytics.FlutterException: PlatformException(error, Failed to find configured root that contains /data/data/com.xxx.xx/app_flutter/account_opening.pdf, null)
at StandardMethodCodec.decodeEnvelope(package:flutter/src/services/message_codecs.dart:564)
at MethodChannel.invokeMethod(package:flutter/src/services/platform_channel.dart:316)
at FlutterEmailSender.send(package:flutter_email_sender/flutter_email_sender.dart:10)
at _EmailWidgetState.build.<fn>(package:gsec/shared/widgets/manualPDFWidget/email_widget.dart:136)
at OnboardingNextButtonWidget.build.<fn>(package:gsec/onboardingScreen/onboard_next_button_widget.dart:84)
at GestureRecognizer.invokeCallback(package:flutter/src/gestures/recognizer.dart:182)
at TapGestureRecognizer._checkUp(package:flutter/src/gestures/tap.dart:365)
at TapGestureRecognizer.acceptGesture(package:flutter/src/gestures/tap.dart:312)
at GestureArenaManager.sweep(package:flutter/src/gestures/arena.dart:156)
at _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent(package:flutter/src/gestures/binding.dart:222)
at _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent(package:flutter/src/gestures/binding.dart:198)
at _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent(package:flutter/src/gestures/binding.dart:156)
at _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue(package:flutter/src/gestures/binding.dart:102)
at _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket(package:flutter/src/gestures/binding.dart:86)
at ._rootRunUnary(dart:async/zone.dart:1136)
at _CustomZone.runUnary(dart:async/zone.dart:1029)
at _CustomZone.runUnaryGuarded(dart:async/zone.dart:931)
at ._invoke1(dart:ui/hooks.dart:250)
at ._dispatchPointerDataPacket(dart:ui/hooks.dart:159)
It is not possible to attach files from ApplicationDocumentsDirectory since this directory is only accessible from your app. You have to use a directory like ExternalStorageDirectory to be able to send from it. If you do so don't forget to add WRITE_EXTERNAL_STORAGE permission to your app before release.
Cheers.

Rx2 java, Consumer interface does not handle error (socket timeout). App crashes

I have the following subscriber for registering an accept from the http service provider, but when the url is malformed, I get an uncatchable exception as shown below, i.e. the try-catch doesn't work. (When the url is valid, no problems).
How do I make this waterproof? I want to receive "onError" but this is not part of the Consumer interface. At the moment, the app crashes on this error event. Perhaps it is better/simpler to use Http directly, instead of RX?
try {
someApi.setStationInfo(stationInfo)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.newThread())
.subscribe(new Consumer<StationInfo>() {
#Override
public void accept(StationInfo abi) throws Exception {
System.out.println("TestAppZappPc received accept from endpoint, data: " + abi);
}
});
} catch (Exception e) {
e.printStackTrace();
}
THE EXCEPTION:
io.reactivex.exceptions.OnErrorNotImplementedException: connect timed out
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
at io.reactivex.internal.observers.LambdaObserver.onError(LambdaObserver.java:77)
at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.checkTerminated(ObservableObserveOn.java:276)
at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:172)
at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
at java.net.Socket.connect(Socket.java:586)
at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:71)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:240)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:160)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:213)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
at com.jakewharton.retrofit2.adapter.rxjava2.CallObservable.subscribeActual(CallObservable.java:41)
at io.reactivex.Observable.subscribe(Observable.java:10955)
at com.jakewharton.retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
2019-05-14 11:41:44.728 31475-32204/com.hdsl.a.zapp E/AndroidRuntime: at io.reactivex.Observable.subscribe(Observable.java:10955)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
... 7 more
There are 2 different ways to handle it.
Use the 2-parameter version of subscribe: subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError). The 2nd Consumer will be called when there's an exception
handle it inline:
someApi.setStationInfo(stationInfo)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.newThread())
.toMaybe()
.onErrorComplete(any -> true)
.subscribe(abi ->
System.out.println("TestAppZappPc received accept from endpoint, data: "
+ abi)
);

Ho to catch flutter video_player plugin error?

How to catch error on flutter video_player plugin?
the error is Source error. when this error occurred I want to display error message.
I/ExoPlayerImpl(31473): Init 98a4284 [ExoPlayerLib/2.9.6] [kenzo, Redmi Note 3, Xiaomi, 23]
E/ExoPlayerImplInternal(31473): Source error.
E/ExoPlayerImplInternal(31473): com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor, AmrExtractor) could read the stream.
E/ExoPlayerImplInternal(31473): at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:973)
E/ExoPlayerImplInternal(31473): at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:891)
E/ExoPlayerImplInternal(31473): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
E/ExoPlayerImplInternal(31473): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
E/ExoPlayerImplInternal(31473): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
E/ExoPlayerImplInternal(31473): at java.lang.Thread.run(Thread.java:818)
I/flutter (31473): Another exception was thrown: A ChewieController was used after being disposed.
I/ExoPlayerImpl(31473): Release 98a4284 [ExoPlayerLib/2.9.6] [kenzo, Redmi Note 3, Xiaomi, 23] [goog.exo.core]
my code
animeVidBloc.vidCtrl = VideoPlayerController.network(streamurl.src)
..initialize().then((_) {
animeVidBloc.vidCtrl.pause();
animeVidBloc.cheCtrl = ChewieController(
videoPlayerController: animeVidBloc.vidCtrl,
aspectRatio: animeVidBloc.vidCtrl.value.aspectRatio,
autoPlay: false,
looping: false,
allowedScreenSleep: false,
);
animeVidBloc.isLoadingData = false;
animeVidBloc.isLoadingVideo = false;
animeVidBloc.cheCtrl.pause();
animeVidBloc.rebuildWidgets(ids: ['body', 'download']);
});
using .catch after initialize().then doesn't catch the error,
example video https://str09.vidoza.net/x4lfoiywwbzpvjumxbaeidisvq6cmoufczvmicnesasm4zqpyunkofpekfla/v.mp4
You can attach listener to the VidePlayerController object to catch states of the controller.
VideoPlayerController _controller = VideoPlayerController.network(
"https://str09.vidoza.net/x4lfoiywwbzpvjumxbaeidisvq6cmoufczvmicnesasm4zqpyunkofpekfla/v.mp4")
..initialize();
_controller.addListener(() {
if (_controller.value.hasError) {
print(_controller.value.errorDescription);
}
if (_controller.value.initialized) {}
if (_controller.value.isBuffering) {}
});