play method
Implementation
Future<void> play(String url) async {
if (url.isEmpty) {
throw ArgumentError('URL cannot be empty');
}
try {
_currentUrl = url;
_state = PlayerState.loading;
_errorMessage = null;
notifyListeners();
// Wait a moment for the platform view to be created if viewId is null
if (Platform.isAndroid && _viewId == null) {
await Future.delayed(const Duration(milliseconds: 100));
}
final params = Platform.isAndroid && _viewId != null
? {'url': url, 'viewId': _viewId}
: {'url': url};
await _channel.invokeMethod('play', params);
} catch (e) {
_state = PlayerState.error;
_errorMessage = e.toString();
notifyListeners();
}
}