Skip to content

Commit

Permalink
updated example app and README
Browse files Browse the repository at this point in the history
  • Loading branch information
asapJ committed Nov 15, 2018
1 parent b8f7ae9 commit 55dd7d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ add the lines to AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
```
NOTE: for android versions >= 6.0 Request Permission from user at runtime before calling this plugin.
NOTE: for android versions >= 6.0 you need might to request Permission from user at runtime before calling this plugin.
(There are available plugins that handles permissions on DartLang.)

#### Add import statement
Import the library
Expand All @@ -26,19 +27,14 @@ Import the library

#### Examples
``` dart
// Fetch thumbnail, store in a specified output folder and return file path
String thumb = await Thumbnails.getThumbnail(
thumbOutputFile:
'[YOUR OUTPUT FOLDER PATH TO SAVE THUMBNAILS]', // creates it if it doesnt already exist
thumbnailFolder:'[FOLDER PATH TO STORE THUMBNAILS]', // creates the specified path if it doesnt exist
videoFile: '[VIDEO PATH HERE]',
imageType: ThumbFormat.PNG,
quality: 30);
// Fetch thumbnail, store in app's Temporary directory output folder and return file path
String thumb = await Thumbnails.getThumbnail(
videoFile: '[VIDEO PATH HERE]',
imageType: ThumbFormat.JPEG,
quality: 45);
/*
* thumbnailFolder property can be omitted if you dont wish to keep the generated thumbails past each usage
*/
```
13 changes: 6 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
// Fetch thumbnail and store in a specified output folder
void _buildThumbToFile() async {
void _toUserFolder() async {
String thumb = await Thumbnails.getThumbnail(
thumbOutputFile:
'/storage/emulated/0/Videos/Thumbnails',
thumbnailFolder: '/storage/emulated/0/Videos/Thumbnails',
videoFile: '/storage/emulated/0/Videos/Testvideo.mp4',
imageType: ThumbFormat.PNG,
quality: 30);
print('path to File: $thumb');
}

// when an output folder is not specified thumbnail are stored in app temporary directory
void _buildThumbToCache() async {
// when an output folder is not specified thumbnail are stored in app temporary directory
void _noFolder() async {
String thumb = await Thumbnails.getThumbnail(
videoFile: '/storage/emulated/0/Videos/Testvideo.mp4',
imageType: ThumbFormat.JPEG,
Expand All @@ -40,9 +39,9 @@ class _MyAppState extends State<MyApp> {
child: Column(
children: <Widget>[
RaisedButton(
onPressed: _buildThumbToFile, child: Text('Build To File')),
onPressed: _toUserFolder, child: Text('To Specified Folder')),
RaisedButton(
onPressed: _buildThumbToCache, child: Text('Build to Cache')),
onPressed: _noFolder, child: Text('No Folder Specified')),
],
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/thumbnails.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class Thumbnails {

static Future<String> getThumbnail(
{@required String videoFile,
String thumbOutputFile,
String thumbnailFolder,
ThumbFormat imageType,
int quality}) async {
var utilMap = <String, dynamic>{
'videoFilePath': videoFile,
'thumbFilePath': thumbOutputFile,
'thumbFilePath': thumbnailFolder,
'thumbnailFormat': validateType(imageType),
'thumbnailQuality': validateQuality(quality)
};
Expand Down
3 changes: 2 additions & 1 deletion lib/validators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const DEFAULT_THUMB_QUALITY = 50;
const DEFAULT_IMAGE_TYPE = ThumbFormat.JPEG;

int validateQuality(int choice) {
if (choice < 10 || choice > 100 || choice == null) return DEFAULT_THUMB_QUALITY;
if (choice < 10 || choice > 100 || choice == null)
return DEFAULT_THUMB_QUALITY;
return choice;
}

Expand Down

0 comments on commit 55dd7d8

Please sign in to comment.