### Define a Single Subtitle Entry Source: https://github.com/fluttercommunity/chewie/blob/master/README.md Structure individual subtitle entries using the `Subtitle` model, specifying its start and end times, and the text content. This model is used within the `Subtitles` list. ```dart Subtitle( index: 0, start: Duration.zero, end: const Duration(seconds: 10), text: 'Hello from subtitles', ), ``` -------------------------------- ### Initialize and use Chewie player Source: https://github.com/fluttercommunity/chewie/blob/master/README.md Initialize a `VideoPlayerController` with a network URL, prepare it, and then create a `ChewieController`. The `Chewie` widget displays the video player. ```dart import 'package:chewie/chewie.dart'; import 'package:video_player/video_player.dart'; final videoPlayerController = VideoPlayerController.networkUrl(Uri.parse( 'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4')); await videoPlayerController.initialize(); final chewieController = ChewieController( videoPlayerController: videoPlayerController, autoPlay: true, looping: true, ); final playerWidget = Chewie( controller: chewieController, ); ``` -------------------------------- ### Add Chewie and video_player to pubspec.yaml Source: https://github.com/fluttercommunity/chewie/blob/master/README.md To use Chewie, add both `chewie` and `video_player` to your project's `pubspec.yaml` file under dependencies. ```yaml dependencies: chewie: video_player: ``` -------------------------------- ### Configure ChewieController with Subtitles Source: https://github.com/fluttercommunity/chewie/blob/master/README.md Integrate subtitles into your video player by providing a `List` to the `ChewieController`. Set `showSubtitles` to true to display them by default and use `subtitleBuilder` for custom rendering. ```dart ChewieController( videoPlayerController: _videoPlayerController, autoPlay: true, looping: true, subtitle: Subtitles([ Subtitle( index: 0, start: Duration.zero, end: const Duration(seconds: 10), text: 'Hello from subtitles', ), Subtitle( index: 1, start: const Duration(seconds: 10), end: const Duration(seconds: 20), text: 'What’s up? :) ), ]), showSubtitles: true, // Automatically display subtitles subtitleBuilder: (context, subtitle) => Container( padding: const EdgeInsets.all(10.0), child: Text( subtitle, style: const TextStyle(color: Colors.white), ), ), ); ``` -------------------------------- ### Migrate Chewie Widget to ChewieController Source: https://github.com/fluttercommunity/chewie/blob/master/README.md Update your Chewie implementation by passing video player controls and options to `ChewieController` instead of directly to the `Chewie` widget. The `Chewie` widget then receives the `ChewieController`. ```dart final playerWidget = Chewie( videoPlayerController, autoPlay: true, looping: true, ); ``` ```dart final chewieController = ChewieController( videoPlayerController: videoPlayerController, autoPlay: true, looping: true, ); final playerWidget = Chewie( controller: chewieController, ); ``` -------------------------------- ### Add Translations for Options Source: https://github.com/fluttercommunity/chewie/blob/master/README.md Provide custom text for options buttons like playback speed and subtitles using `optionsTranslation`. This is useful for internationalization. ```dart optionsTranslation: OptionsTranslation( playbackSpeedButtonText: 'Wiedergabegeschwindigkeit', subtitlesButtonText: 'Untertitel', cancelButtonText: 'Abbrechen', ), ``` -------------------------------- ### Android Buffering Workaround Source: https://github.com/fluttercommunity/chewie/blob/master/README.md This workaround addresses an Android-specific issue where the buffering state is not reported correctly, leading to the loading spinner being constantly displayed. It involves listening to the video controller's state and manually playing the video if it was paused and seeking occurred. ```dart // Your init code can be above videoController.addListener(yourListeningMethod); // ... bool wasPlayingBefore = false; void yourListeningMethod() { if (!videoController.isPlaying && !wasPlayingBefore) { // -> Workaround if seekTo another position while it was paused before. // On Android this might lead to infinite loading, so just play the // video again. videoController.play(); } wasPlayingBefore = videoController.value.isPlaying; // ... } ``` -------------------------------- ### Add custom options to ChewieController Source: https://github.com/fluttercommunity/chewie/blob/master/README.md You can add custom options to the Chewie player's settings menu by providing a list of `OptionItem` objects to the `additionalOptions` parameter in `ChewieController`. ```dart additionalOptions: (context) { return [ OptionItem( onTap: () => debugPrint('My option works!'), iconData: Icons.chat, title: 'My localized title', ), OptionItem( onTap: () => debugPrint('Another option that works!'), iconData: Icons.chat, title: 'Another localized title', ), ]; }, ``` -------------------------------- ### Dispose Chewie and VideoPlayer controllers Source: https://github.com/fluttercommunity/chewie/blob/master/README.md Ensure that both `videoPlayerController` and `chewieController` are disposed of properly to prevent memory leaks, typically by overriding the `dispose` method in a `StatefulWidget`. ```dart @override void dispose() { videoPlayerController.dispose(); chewieController.dispose(); super.dispose(); } ``` -------------------------------- ### Customize Options Sheet with optionsBuilder Source: https://github.com/fluttercommunity/chewie/blob/master/README.md Override the default modal sheet for options using `optionsBuilder`. This allows for custom dialogs like `AlertDialog` to display options. Ensure `defaultOptions` are handled within your custom builder. ```dart optionsBuilder: (context, defaultOptions) async { await showDialog( context: context, builder: (ctx) { return AlertDialog( content: ListView.builder( itemCount: defaultOptions.length, itemBuilder: (_, i) => ActionChip( label: Text(defaultOptions[i].title), onPressed: () => defaultOptions[i].onTap!(), ), ), ); }, ); }, ``` -------------------------------- ### Disable Android Loading Spinner Source: https://github.com/fluttercommunity/chewie/blob/master/README.md To completely fix the Android buffering issue, you can disable the loading spinner by setting a very large duration for `progressIndicatorDelay`. Be aware that this will also hide the indicator when the video is legitimately buffering. ```dart _chewieController = ChewieController( videoPlayerController: _videoPlayerController, progressIndicatorDelay: Platform.isAndroid ? const Duration(days: 1) : null, ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.