Last active
January 13, 2021 00:12
-
-
Save jtmuller5/c489f0fa52a77876df527b48509760db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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