ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Youtube player
    Flutter 2023. 9. 26. 09:16

    pubspec.yaml

    dependencies:
      flutter:
        sdk: flutter
    
      # The following adds the Cupertino Icons font to your application.
      # Use with the CupertinoIcons class for iOS style icons.
      youtube_player_flutter: ^8.0.0

     

    console

    flutter pub get

     

    xxx.dart

    class Xxx extends StatefulWidget {
      @override
      State<StatefulWidget> createState() => _Xxx();
    }
    
    class _Xxx extends State<Xxx> {
      YoutubePlayerController? _youtubeController;
      String? _videoId;
      
      @override
      void initState() {
        // TODO: implement initState
        _videoId = 'ghAURtdskUY'; // https://youtu.be/ghAURtdskUY
        initYoutubePlayer();
        super.initState();
      }
      
      void initYoutubePlayer() {
        _youtubeController = YoutubePlayerController(
          initialVideoId: _videoId!,
          flags: const YoutubePlayerFlags(
            mute: false,
            autoPlay: true,
            disableDragSeek: false,
            loop: false,
            isLive: false,
            forceHD: false,
            enableCaption: false,
          ),
        );
      }
      
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: SingleChildScrollView(
            child: SafeArea(
              child: Center(
                child: Column(
                  children: [
                    SizedBox(
                      child: YoutubePlayer(
                        controller: _youtubeController,
                        actionsPadding: EdgeInsets.all(16.0),
                        bottomActions: [
                          CurrentPosition(),
                          SizedBox(width: 10.0),
                          ProgressBar(isExpanded: true),
                          SizedBox(width: 10.0),
                          RemainingDuration(),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
        );
    }

    'Flutter' 카테고리의 다른 글

    WebView  (0) 2023.09.26
Designed by Tistory.