How can I capture youtube player state changes with the youtube_player_iframe library?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AndresCidInst
    New Member
    • Jan 2023
    • 1

    How can I capture youtube player state changes with the youtube_player_iframe library?

    Using the youtube_player_ iframe library I was able to capture some video status data (playing, paused, with/without audio) for xAPI statemetns, but from external buttons, not from the player itself.

    Video player
    Code:
      Widget oneVideo(BuildContext context, double heigth, double width) {
        return SingleChildScrollView(
            child: Column(
          children: [
            SizedBox(
              height: heigth,
              width: width,
              child: YoutubePlayer(
                controller: _controller,
                backgroundColor: Colors.black,
              ),
            ),
          ],
        ));
      }
    My custom buttons
    Code:
    Row optionButtons(BuildContext context) {
        return Row(
          children: [
            YoutubeValueBuilder(
              builder: (context, value) {
                return IconButton(
                  icon: Icon(
                    value.playerState == PlayerState.playing
                        ? Icons.pause
                        : Icons.play_arrow,
                  ),
                  onPressed: () {
                    if (value.playerState == PlayerState.playing) {
                      context.ytController.pauseVideo();
                      pausePlay(
                          "Pause", "WatchTemplateVideo", context.ytController);
                    } else {
                      context.ytController.playVideo();
                      pausePlay("Play", "WatchTemplateVideo", context.ytController);
                    }
                  },
                );
              },
            )
          ],
        );
      }
    The clasws builder
    Code:
    Widget build(BuildContext context) {
        double heigth = MediaQuery.of(context).size.height * 0.7;
        double width = MediaQuery.of(context).size.width * 0.7;
        return YoutubePlayerScaffold(
            controller: _controller,
            builder: (context, player) {
              return YoutubePlayerControllerProvider(
                controller: _controller,
                child: Column(
                  children: [
                    oneVideo(context, heigth, width),
                    optionButtons(context)
                  ],
                ),
              );
            });
      }
    However I have not been able to get it to capture the data from the internal controls of the player. I would be very grateful for your help :" )
Working...