minor fixes
This commit is contained in:
parent
cfd5051c69
commit
6b299f6c86
2 changed files with 24 additions and 18 deletions
|
@ -103,12 +103,10 @@ public class ImageFileHandler implements MethodChannel.MethodCallHandler {
|
||||||
Glide.with(activity).clear(target);
|
Glide.with(activity).clear(target);
|
||||||
} else {
|
} else {
|
||||||
ContentResolver cr = activity.getContentResolver();
|
ContentResolver cr = activity.getContentResolver();
|
||||||
try (InputStream is = cr.openInputStream(uri)) {
|
|
||||||
if (is != null) {
|
|
||||||
data = getBytes(is);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && (MimeTypes.HEIC.equals(mimeType) || MimeTypes.HEIF.equals(mimeType))) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && (MimeTypes.HEIC.equals(mimeType) || MimeTypes.HEIF.equals(mimeType))) {
|
||||||
// as of Flutter v1.15.17, Dart Image.memory cannot decode HEIF/HEIC images
|
// as of Flutter v1.15.17, Dart Image.memory cannot decode HEIF/HEIC images
|
||||||
// so we convert the image using Android native decoder
|
// so we convert the image using Android native decoder
|
||||||
|
try {
|
||||||
ImageDecoder.Source source = ImageDecoder.createSource(cr, uri);
|
ImageDecoder.Source source = ImageDecoder.createSource(cr, uri);
|
||||||
Bitmap bitmap = ImageDecoder.decodeBitmap(source);
|
Bitmap bitmap = ImageDecoder.decodeBitmap(source);
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
@ -116,13 +114,21 @@ public class ImageFileHandler implements MethodChannel.MethodCallHandler {
|
||||||
// Bitmap.CompressFormat.PNG is slower than JPEG
|
// Bitmap.CompressFormat.PNG is slower than JPEG
|
||||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream);
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream);
|
||||||
data = stream.toByteArray();
|
data = stream.toByteArray();
|
||||||
|
} catch (IOException e) {
|
||||||
|
result.error("getImage-decode-exception", "failed to decode image from uri=" + uri, e.getMessage());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
try (InputStream is = cr.openInputStream(uri)) {
|
||||||
|
if (is != null) {
|
||||||
|
data = getBytes(is);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
result.error("getImage-image-exception", "failed to get image from uri=" + uri, e.getMessage());
|
result.error("getImage-read-exception", "failed to get image from uri=" + uri, e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
result.success(data);
|
result.success(data);
|
||||||
|
|
|
@ -56,7 +56,7 @@ class AvesVideoState extends State<AvesVideo> {
|
||||||
..clear();
|
..clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPlayable(IjkStatus status) => [IjkStatus.prepared, IjkStatus.playing, IjkStatus.pause, IjkStatus.complete].contains(status);
|
bool isPlayable(IjkStatus status) => controller != null && [IjkStatus.prepared, IjkStatus.playing, IjkStatus.pause, IjkStatus.complete].contains(status);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
Loading…
Reference in a new issue