Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Last active January 13, 2021 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtmuller5/c489f0fa52a77876df527b48509760db to your computer and use it in GitHub Desktop.
Save jtmuller5/c489f0fa52a77876df527b48509760db to your computer and use it in GitHub Desktop.
class StackedVideoViewModel extends BaseViewModel {
// Input Properties
VideoPlayerController videoPlayerController;
bool showFull;
double x; // X alignment of FittedBox
double y; // Y alignment of FittedBox
// Local Properties
bool gotThumbnailSize = false;
double thumbnailWidth = 300;
double thumbnailHeight = 200;
/// Keys
GlobalKey thumbnailKey = GlobalObjectKey('video_thumbnail');
void initialize(String videoUrl, bool full,double inx, double iny) {
showFull = full;
x = inx;
y = iny;
videoPlayerController = VideoPlayerController.network(videoUrl);
videoPlayerController.initialize().then((value) {
videoPlayerController.setLooping(true);
notifyListeners();
});
}
void playVideo(){
videoPlayerController.play();
notifyListeners();
}
void pauseVideo(){
videoPlayerController.pause();
notifyListeners();
}
void getVideoSize(){
/// (4) Get the RenderBox from the GlobalObjectKey and extract it's size
RenderBox render = thumbnailKey.currentContext.findRenderObject() as RenderBox;
thumbnailWidth = render.size.width;
thumbnailHeight = render.size.height;
gotThumbnailSize = true;
/// (5) Update the Views
notifyListeners();
}
@override
void dispose() {
videoPlayerController.dispose();
super.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment