Unable to play .m3u8 file with flutter package better player - flutter

I have a .m3u8 file that contains information about a video but I am unable to play it using the BetterPlayer Flutter package.
This is my sample code
var dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.file,
"/var/mobile/Containers/Data/Application/B0391873-25D4-471A-AB13-05D5FF8701F9/Documents/content.publicId/test.m3u8",
subtitles: null,
headers: {"cookie":"COOKIE_FOR_AWS_CLOUDFRONT_ACCESS"},
liveStream: true
);
But I keep getting this error:
GetDataFromUrl failed: Invalid argument(s): No host specified in URI /var/mobile/Containers/Data/Application/FE19C886-73B8-49C0-A770-6BAEAD354947/Documents/content.publicId/test.m3u8
Failed to load video: Error Domain=CoreMediaErrorDomain Code=-12865
"(null)" [VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception:
PlatformException(VideoError, Failed to load video: The operation
couldn’t be completed. (CoreMediaErrorDomain error -12865.), null,
null)
These are the contents of the .m3u8 file:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:37
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=AES-128, URI="https://PATH_TO_ENCRYPTION_KEY",IV=0x413873f3924c752d99c7083c0c99931c
#EXTINF:36.440000, https://example.com/test_480p_0000.ts
#EXTINF:28.040000, https://example.com/test_480p_0001.ts
#EXTINF:28.360000, https://example.com/test_480p_0002.ts
#EXTINF:29.920000, https://example.com/test_480p_0003.ts
#EXTINF:36.920000, https://example.com/test_480p_0004.ts
#EXTINF:21.040000, https://example.com/test_480p_0005.ts
#EXT-X-ENDLIST

Related

Unable to build flutter application after updating

I am unable to build flutter application using the following environment
environment:
sdk: '>=2.18.5 <3.0.0'
I am getting below error
Error output from Xcode build:
error: the following command failed with exit code 0 but produced no further output
error: the following command failed with exit code 0 but produced no further output
: Error: Type 'EditableTextContextMenuBuilder' not found.
text_field.dart:558
: Error: Method 'insert' cannot be called on 'OverlayState?' because it is potentially null.
search_field.dart:244
: Error: Undefined name 'CupertinoAdaptiveTextSelectionToolbar'.
text_field.dart:442
: Error: 'EditableTextContextMenuBuilder' isn't a type.
text_field.dart:558
: Error: 'EditableTextContextMenuBuilder' isn't a type.
text_field.dart:870
: Error: No named parameter with the name 'contextMenuBuilder'.
text_field.dart:1395
: Error: A value of type 'OverlayState?' can't be assigned to a variable of type 'OverlayState' because 'OverlayState?' is nullable and 'OverlayState' isn't.
tooltip.dart:170
: Error: Method 'writeState' cannot be called on 'PageStorageBucket?' because it is potentially null.

Flutter: Exception: Invalid image data: Failed to decode image while loading image ( over ngrok )

I have uploaded an image through my flutter web application to my node-js backend. the file is uploaded fine and I can view it in VS code. I have "ngrok" running so I can connect with my flutter mobile application. but when I try and load the image in the mobile application this is what I get.
E/FlutterJNI(24257): Failed to decode image
E/FlutterJNI(24257): android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error.
E/FlutterJNI(24257): at android.graphics.ImageDecoder.nCreate(Native Method)
E/FlutterJNI(24257): at android.graphics.ImageDecoder.access$200(ImageDecoder.java:173)
E/FlutterJNI(24257): at android.graphics.ImageDecoder$ByteBufferSource.createImageDecoder(ImageDecoder.java:250)
E/FlutterJNI(24257): at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1862)
E/FlutterJNI(24257): at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1855)
E/FlutterJNI(24257): at io.flutter.embedding.engine.FlutterJNI.decodeImage(FlutterJNI.java:524)
════════ Exception caught by image resource service ════════════════════════════
The following _Exception was thrown resolving an image codec:
Exception: Invalid image data
When the exception was thrown, this was the stack
#0 _futurize (dart:ui/painting.dart:5718:5)
#1 ImageDescriptor.encoded (dart:ui/painting.dart:5574:12)
#2 instantiateImageCodec (dart:ui/painting.dart:2056:60)
<asynchronous suspension>
Image provider: NetworkImage("https://ff8c-119-153-136-128.ngrok.io/uploads\banners\1660405360606-MicrosoftTeams-image.png", scale: 1.0)
Image key: NetworkImage("https://ff8c-119-153-136-128.ngrok.io/uploads\banners\1660405360606-MicrosoftTeams-image.png", scale: 1.
Although if I open the image the URL directly inside the browser, it loads fine.
P.S. I am uploading the image from the web app in bytes form using the file picker package.
This is the code to load the image:
CachedNetworkImage(
imageUrl: baseURL + banner.imageUrl!,
height: 120.h,
width: double.infinity,
fit: BoxFit.cover,
progressIndicatorBuilder: (context, str, progress) {
return SizedBox(
height: 120.h,
child: const Center(
child: CircularProgressIndicator.adaptive(),
),
);
},
),
I can't verify if the problem is because of ngrok or because the file is uploaded in bytes form.
Turns out, that it's the backward slash in the URL that is the problem. If I open the URL in the browser it automatically replaces "" with "/". But it doesn't happen in Flutter when loading the image.

How to convert Uint8List to Image Data Type

The below code is converting png image to Image DataType but it is not converting SVG image to Image DataType.
var decodedImage = await decodeImageFromList(img.buffer.asUint8List()); // This is not working for SVG images.
Getting error:-
E/FlutterJNI( 9122): Failed to decode image
E/FlutterJNI( 9122): android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error.
E/FlutterJNI( 9122): at android.graphics.ImageDecoder.nCreate(Native Method)
E/FlutterJNI( 9122): at android.graphics.ImageDecoder.access$200(ImageDecoder.java:173)
E/FlutterJNI( 9122): at android.graphics.ImageDecoder$ByteBufferSource.createImageDecoder(ImageDecoder.java:250)
E/FlutterJNI( 9122): at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1862)
E/FlutterJNI( 9122): at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1855)
E/FlutterJNI( 9122): at io.flutter.embedding.engine.FlutterJNI.decodeImage(FlutterJNI.java:431)
I/flutter ( 9122): Exception: Invalid image data
SVGs aren't supported in the Image class. Use flutter_svg and then pass your Uint8List to SvgPicture.memory(yourUint8List)

Unhandled Exception: FileSystemException: Cannot retrieve length of file

When I try to rename a File it throws a FileSystemException Exception
this is the exception:
E/flutter (12252): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot retrieve length of file, path = '' (OS Error: No such file or directory, errno = 2)
this is the code:
for (String path in _files.paths)
{
for (File file in _pickedFiles)
{
if(file.path == path)
{
await _pickedFiles.last.rename(_path.withoutExtension(file.path) + '()' + _path.extension(file.path));
}
}
}
Please help me
Thank you.

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.