video_trimmer 0.2.6 video_trimmer: ^0.2.6 copied to clipboard
A Flutter package for trimming videos. This supports retrieving, trimming, and storage of trimmed video files to the file system.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:video_trimmer/trim_editor.dart';
import 'package:video_trimmer/video_trimmer.dart';
import 'package:video_trimmer/video_viewer.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Trimmer',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
final Trimmer _trimmer = Trimmer();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Video Trimmer"),
),
body: Center(
child: Container(
child: RaisedButton(
child: Text("LOAD VIDEO"),
onPressed: () async {
File file = await ImagePicker.pickVideo(
source: ImageSource.gallery,
);
if (file != null) {
await _trimmer.loadVideo(videoFile: file);
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return TrimmerView(_trimmer);
}));
}
},
),
),
),
);
}
}
class TrimmerView extends StatefulWidget {
final Trimmer _trimmer;
TrimmerView(this._trimmer);
@override
_TrimmerViewState createState() => _TrimmerViewState();
}
class _TrimmerViewState extends State<TrimmerView> {
double _startValue = 0.0;
double _endValue = 0.0;
bool _isPlaying = false;
bool _progressVisibility = false;
Future<String> _saveVideo() async {
setState(() {
_progressVisibility = true;
});
String _value;
await widget._trimmer
.saveTrimmedVideo(startValue: _startValue, endValue: _endValue)
.then((value) {
setState(() {
_progressVisibility = false;
_value = value;
});
});
return _value;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Video Trimmer"),
),
body: Builder(
builder: (context) => Center(
child: Container(
padding: EdgeInsets.only(bottom: 30.0),
color: Colors.black,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Visibility(
visible: _progressVisibility,
child: LinearProgressIndicator(
backgroundColor: Colors.red,
),
),
RaisedButton(
onPressed: _progressVisibility
? null
: () async {
_saveVideo().then((outputPath) {
print('OUTPUT PATH: $outputPath');
final snackBar = SnackBar(
content: Text('Video Saved successfully'),
);
Scaffold.of(context).showSnackBar(snackBar);
});
},
child: Text("SAVE"),
),
Expanded(
child: VideoViewer(),
),
Center(
child: TrimEditor(
viewerHeight: 50.0,
viewerWidth: MediaQuery.of(context).size.width,
onChangeStart: (value) {
_startValue = value;
},
onChangeEnd: (value) {
_endValue = value;
},
onChangePlaybackState: (value) {
setState(() {
_isPlaying = value;
});
},
),
),
FlatButton(
child: _isPlaying
? Icon(
Icons.pause,
size: 80.0,
color: Colors.white,
)
: Icon(
Icons.play_arrow,
size: 80.0,
color: Colors.white,
),
onPressed: () async {
bool playbackState =
await widget._trimmer.videPlaybackControl(
startValue: _startValue,
endValue: _endValue,
);
setState(() {
_isPlaying = playbackState;
});
},
)
],
),
),
),
),
);
}
}