ensureInitialized static method
void
ensureInitialized()
Ensures that the necessary initializations for YPlayer are performed.
This method checks if initialization has already occurred. If not, it:
- Initializes Flutter's widget binding.
- Initializes the MediaKit library.
- Sets the _isInitialized flag to true to prevent future reinitializations.
Usage: Call this method in your app's main function or before using any YPlayer functionality. Example:
void main() {
YPlayerInitializer.ensureInitialized();
runApp(MyApp());
}
Implementation
static void ensureInitialized() {
// Check if initialization has already been performed
if (!_isInitialized) {
// Initialize Flutter's widget binding
// This is necessary for Flutter to set up the engine and render the UI
WidgetsFlutterBinding.ensureInitialized();
// Initialize the MediaKit library
// This sets up the necessary components for media playback
MediaKit.ensureInitialized();
// Set the flag to true to indicate that initialization has been completed
_isInitialized = true;
}
// If _isInitialized is already true, this method does nothing,
// effectively preventing redundant initializations
}