subtitle_wrapper_package 3.0.0-dev.1 copy "subtitle_wrapper_package: ^3.0.0-dev.1" to clipboard
subtitle_wrapper_package: ^3.0.0-dev.1 copied to clipboard

A Subtitle Wrapper package, this subtitle wrapper package displays subtitles for a video player.

example/lib/main.dart

import 'package:chewie/chewie.dart';
import 'package:example/data/sw_constants.dart';
import 'package:flutter/material.dart';
import 'package:subtitle_wrapper_package/subtitle_wrapper_package.dart';
import 'package:video_player/video_player.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({
    super.key,
  });

  @override
  MyHomePageState createState() => MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  final String link = SwConstants.videoUrl;
  late ChewieController _chewieController;
  final SubtitleController subtitleController = SubtitleController(
    subtitleUrl: SwConstants.enSubtitle,
    subtitleDecoder: SubtitleDecoder.utf8,
    subtitleStyle: const TextStyle(
      color: Colors.white,
      fontWeight: FontWeight.bold,
    ),
  );

  @override
  void initState() {
    _chewieController = chewieController;
    super.initState();
  }

  VideoPlayerController get videoPlayerController {
    return VideoPlayerController.networkUrl(Uri.parse(link));
  }

  ChewieController get chewieController {
    return ChewieController(
      videoPlayerController: videoPlayerController,
      aspectRatio: 3 / 2,
      autoPlay: true,
      autoInitialize: true,
      routePageBuilder: (context, animation, secondaryAnimation, controllerProvider) {
        return SubtitleRoutePage(
          subtitleController: subtitleController,
          videoPlayerController: controllerProvider.controller.videoPlayerController,
          videoChild: _VideoChild(
            chewieController: controllerProvider.controller,
          ),
        );
      },
    );
  }

  void updateSubtitleUrl({
    required ExampleSubtitleLanguage subtitleLanguage,
  }) {
    String? subtitleUrl;
    switch (subtitleLanguage) {
      case ExampleSubtitleLanguage.english:
        subtitleUrl = SwConstants.enSubtitle;
        break;
      case ExampleSubtitleLanguage.spanish:
        subtitleUrl = SwConstants.esSubtitle;
        break;
      case ExampleSubtitleLanguage.dutch:
        subtitleUrl = SwConstants.nlSubtitle;
        break;
    }
    subtitleController.updateSubtitleUrl(
      url: subtitleUrl,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xff0b090a),
      body: Column(
        children: [
          Padding(
            padding: EdgeInsets.only(
              top: MediaQuery.of(context).padding.top,
            ),
            child: SizedBox(
              height: 270,
              child: SubtitleWrapper(
                videoPlayerController: _chewieController.videoPlayerController,
                subtitleController: subtitleController,
                videoChild: _VideoChild(
                  chewieController: _chewieController,
                ),
              ),
            ),
          ),
          Expanded(
            child: ColoredBox(
              color: const Color(
                0xff161a1d,
              ),
              child: Row(
                children: [
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.all(
                        16.0,
                      ),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            'Flutter subtitle wrapper package',
                            style: TextStyle(
                              fontSize: 28.0,
                              color: Colors.white.withOpacity(
                                0.8,
                              ),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.symmetric(
                              vertical: 18.0,
                            ),
                            child: Text(
                              'This package can display SRT and WebVtt subtitles. With a lot of customizable options and dynamic updating support.',
                              style: TextStyle(
                                fontSize: 14.0,
                                color: Colors.white.withOpacity(
                                  0.8,
                                ),
                              ),
                            ),
                          ),
                          Text(
                            'Options.',
                            style: TextStyle(
                              fontSize: 14.0,
                              color: Colors.white.withOpacity(
                                0.8,
                              ),
                            ),
                          ),
                          const Divider(
                            color: Colors.grey,
                          ),
                          Wrap(
                            children: [
                              ElevatedButton(
                                style: ButtonStyle(
                                  elevation: MaterialStateProperty.all<double>(8.0),
                                  shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                                    RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(
                                        8.0,
                                      ),
                                    ),
                                  ),
                                ),
                                onPressed: () => updateSubtitleUrl(
                                  subtitleLanguage: ExampleSubtitleLanguage.english,
                                ),
                                child: const Text('Switch to 🇬🇧'),
                              ),
                              const SizedBox(
                                width: 8.0,
                              ),
                              ElevatedButton(
                                style: ButtonStyle(
                                  elevation: MaterialStateProperty.all<double>(8.0),
                                  shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                                    RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(
                                        8.0,
                                      ),
                                    ),
                                  ),
                                ),
                                onPressed: () => updateSubtitleUrl(
                                  subtitleLanguage: ExampleSubtitleLanguage.spanish,
                                ),
                                child: const Text('Switch to 🇪🇸'),
                              ),
                              const SizedBox(
                                width: 8.0,
                              ),
                              ElevatedButton(
                                style: ButtonStyle(
                                  elevation: MaterialStateProperty.all<double>(8.0),
                                  shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                                    RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(
                                        8.0,
                                      ),
                                    ),
                                  ),
                                ),
                                onPressed: () => updateSubtitleUrl(
                                  subtitleLanguage: ExampleSubtitleLanguage.dutch,
                                ),
                                child: const Text('Switch to 🇳🇱'),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    _chewieController.dispose();
  }
}

class _VideoChild extends StatelessWidget {
  const _VideoChild({
    required this.chewieController,
    super.key,
  });

  final ChewieController chewieController;

  @override
  Widget build(BuildContext context) {
    return Chewie(
      controller: chewieController,
    );
  }
}

enum ExampleSubtitleLanguage {
  english,
  spanish,
  dutch,
}
72
likes
150
points
1.39k
downloads

Publisher

verified publisherjorandob.nl

Weekly Downloads

A Subtitle Wrapper package, this subtitle wrapper package displays subtitles for a video player.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bloc, equatable, flutter, flutter_bloc, http, http_parser, video_player

More

Packages that depend on subtitle_wrapper_package