import 'package:bloc/bloc.dart'; import 'package:teso/Services/services2.dart'; import 'video_player.dart'; class VideoPlayerBloc extends Bloc { final VideoControllerService _videoControllerService; VideoPlayerBloc(this._videoControllerService) : assert(_videoControllerService != null), super(null); VideoPlayerState get initialState => VideoPlayerStateInitial(); @override Stream mapEventToState(VideoPlayerEvent event) async* { if (event is VideoSelectedEvent) { yield VideoPlayerStateLoading(); try { final videoController = await _videoControllerService.getControllerForVideo(event.video); yield VideoPlayerStateLoaded(event.video, videoController); } catch (e) { yield VideoPlayerStateError(e.message ?? 'An unknown error occurred'); } } } }