Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix with gradle 8, Dart 3 #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
namespace "xyz.justsoft.video_thumbnail"
compileSdkVersion 33

defaultConfig {
Expand Down
93 changes: 39 additions & 54 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'dart:io';

import 'package:video_thumbnail/video_thumbnail.dart';
import 'package:image_picker/image_picker.dart';
Expand All @@ -29,58 +28,43 @@ class ThumbnailRequest {
final int quality;

const ThumbnailRequest(
{this.video,
this.thumbnailPath,
this.imageFormat,
this.maxHeight,
this.maxWidth,
this.timeMs,
this.quality});
{required this.video,
required this.thumbnailPath,
required this.imageFormat,
required this.maxHeight,
required this.maxWidth,
required this.timeMs,
required this.quality});
}

class ThumbnailResult {
final Image image;
final int dataSize;
final int height;
final int width;
const ThumbnailResult({this.image, this.dataSize, this.height, this.width});
const ThumbnailResult(
{required this.image,
required this.dataSize,
required this.height,
required this.width});
}

Future<ThumbnailResult> genThumbnail(ThumbnailRequest r) async {
//WidgetsFlutterBinding.ensureInitialized();
Uint8List bytes;
final Completer<ThumbnailResult> completer = Completer();
if (r.thumbnailPath != null) {
final thumbnailPath = await VideoThumbnail.thumbnailFile(
video: r.video,
headers: {
"USERHEADER1": "user defined header1",
"USERHEADER2": "user defined header2",
},
thumbnailPath: r.thumbnailPath,
imageFormat: r.imageFormat,
maxHeight: r.maxHeight,
maxWidth: r.maxWidth,
timeMs: r.timeMs,
quality: r.quality);

print("thumbnail file is located: $thumbnailPath");

final file = File(thumbnailPath);
bytes = file.readAsBytesSync();
} else {
bytes = await VideoThumbnail.thumbnailData(
video: r.video,
headers: {
"USERHEADER1": "user defined header1",
"USERHEADER2": "user defined header2",
},
imageFormat: r.imageFormat,
maxHeight: r.maxHeight,
maxWidth: r.maxWidth,
timeMs: r.timeMs,
quality: r.quality);
}
bytes = (await VideoThumbnail.thumbnailData(
video: r.video,
headers: {
"USERHEADER1": "user defined header1",
"USERHEADER2": "user defined header2",
},
imageFormat: r.imageFormat,
maxHeight: r.maxHeight,
maxWidth: r.maxWidth,
timeMs: r.timeMs,
quality: r.quality))!;

int _imageDataSize = bytes.length;
print("image size: $_imageDataSize");
Expand All @@ -102,7 +86,8 @@ Future<ThumbnailResult> genThumbnail(ThumbnailRequest r) async {
class GenThumbnailImage extends StatefulWidget {
final ThumbnailRequest thumbnailRequest;

const GenThumbnailImage({Key key, this.thumbnailRequest}) : super(key: key);
const GenThumbnailImage({Key? key, required this.thumbnailRequest})
: super(key: key);

@override
_GenThumbnailImageState createState() => _GenThumbnailImageState();
Expand All @@ -125,7 +110,7 @@ class _GenThumbnailImageState extends State<GenThumbnailImage> {
children: <Widget>[
Center(
child: Text(
"Image ${widget.thumbnailRequest.thumbnailPath == null ? 'data size' : 'file size'}: $_dataSize, width:$_width, height:$_height"),
"Image file size: $_dataSize, width:$_width, height:$_height"),
),
Container(
color: Colors.grey,
Expand Down Expand Up @@ -183,9 +168,9 @@ class _DemoHomeState extends State<DemoHome> {
int _sizeW = 0;
int _timeMs = 0;

GenThumbnailImage _futreImage;
late GenThumbnailImage _futreImage;

String _tempDir;
late String _tempDir;

@override
void initState() {
Expand Down Expand Up @@ -275,7 +260,7 @@ class _DemoHomeState extends State<DemoHome> {
groupValue: _format,
value: ImageFormat.JPEG,
onChanged: (v) => setState(() {
_format = v;
_format = v!;
_editNode.unfocus();
}),
),
Expand All @@ -289,7 +274,7 @@ class _DemoHomeState extends State<DemoHome> {
groupValue: _format,
value: ImageFormat.PNG,
onChanged: (v) => setState(() {
_format = v;
_format = v!;
_editNode.unfocus();
}),
),
Expand All @@ -303,7 +288,7 @@ class _DemoHomeState extends State<DemoHome> {
groupValue: _format,
value: ImageFormat.WEBP,
onChanged: (v) => setState(() {
_format = v;
_format = v!;
_editNode.unfocus();
}),
),
Expand Down Expand Up @@ -349,7 +334,7 @@ class _DemoHomeState extends State<DemoHome> {
child: ListView(
shrinkWrap: true,
children: <Widget>[
(_futreImage != null) ? _futreImage : SizedBox(),
_futreImage,
],
),
),
Expand Down Expand Up @@ -379,10 +364,10 @@ class _DemoHomeState extends State<DemoHome> {
children: <Widget>[
FloatingActionButton(
onPressed: () async {
File video =
await ImagePicker.pickVideo(source: ImageSource.camera);
XFile? video =
await ImagePicker().pickImage(source: ImageSource.camera);
setState(() {
_video.text = video.path;
_video.text = video!.path;
});
},
child: Icon(Icons.videocam),
Expand All @@ -393,10 +378,10 @@ class _DemoHomeState extends State<DemoHome> {
),
FloatingActionButton(
onPressed: () async {
File video =
await ImagePicker.pickVideo(source: ImageSource.gallery);
XFile? video =
await ImagePicker().pickVideo(source: ImageSource.gallery);
setState(() {
_video.text = video?.path;
_video.text = video!.path;
});
},
child: Icon(Icons.local_movies),
Expand All @@ -412,7 +397,7 @@ class _DemoHomeState extends State<DemoHome> {
_futreImage = GenThumbnailImage(
thumbnailRequest: ThumbnailRequest(
video: _video.text,
thumbnailPath: null,
thumbnailPath: '',
imageFormat: _format,
maxHeight: _sizeH,
maxWidth: _sizeW,
Expand Down
Loading