sarbagyastha / youtube_player_flutter

A Flutter plugin for inline playback or streaming of YouTube videos using the official iFrame Player API.
https://youtube.sarbagyastha.com.np
BSD 3-Clause "New" or "Revised" License
713 stars 829 forks source link

[BUG] YoutubePlayerBuilder "onExitFullScreen" is called multiple times and on widget build lifecycle #705

Open adummy832 opened 2 years ago

adummy832 commented 2 years ago

Describe the bug

To Reproduce

import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:youtube_player_flutter/youtube_player_flutter.dart';

import 'video_list.dart';

void main() { WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky); SystemChrome.setSystemUIOverlayStyle( const SystemUiOverlayStyle(statusBarColor: Colors.blueAccent), ); runApp(const YoutubePlayerDemoApp()); }

/// Creates [YoutubePlayerDemoApp] widget. class YoutubePlayerDemoApp extends StatelessWidget { const YoutubePlayerDemoApp({super.key});

@override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Youtube Player Flutter', theme: ThemeData( primarySwatch: Colors.blue, appBarTheme: const AppBarTheme( color: Colors.blueAccent, titleTextStyle: TextStyle( color: Colors.white, fontWeight: FontWeight.w300, fontSize: 20, ), ), iconTheme: const IconThemeData( color: Colors.blueAccent, ), ), home: const MyHomePage(), ); } }

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

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

class _MyHomePageState extends State { late YoutubePlayerController _controller; late PlayerState _playerState;

final List _ids = [ 'nPt8bK2gbaU', 'gQDByCdjUXw', 'iLnmTe5Q2Qw', '_WoCV4c6XOE', 'KmzdUe0RSJo', '6jZDSSZZxjQ', 'p2lYr3vM1w', '7QUtEmBT-w', '34_PXCzGw1M', ];

@override void initState() { super.initState(); _controller = YoutubePlayerController( initialVideoId: _ids.first, flags: const YoutubePlayerFlags( mute: false, autoPlay: false, disableDragSeek: false, loop: false, isLive: false, forceHD: false, enableCaption: true, ), )..addListener(listener); _playerState = PlayerState.unknown; }

void listener() { setState(() { _playerState = _controller.value.playerState; }); }

@override void deactivate() { // Pauses video while navigating to next page. _controller.pause(); super.deactivate(); }

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

@override Widget build(BuildContext context) { return YoutubePlayerBuilder( onEnterFullScreen: () { print('YOUTUBE_PLAYER: ON_ENTER_CALLED'); SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight, ]); }, onExitFullScreen: () { print('YOUTUBE_PLAYER: ON_EXIT_CALLED'); SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown, ]); }, player: YoutubePlayer( controller: _controller, showVideoProgressIndicator: true, progressIndicatorColor: Colors.blueAccent, ), builder: (context, player) => Scaffold( appBar: AppBar( title: const Text( 'Youtube Player Flutter', style: TextStyle(color: Colors.white), ), ), body: player, persistentFooterButtons: const [ Text('Testing'), ], ), ); } }



**Expected behavior**
* Must only call this function upon exit of fullscreen video

**Screenshots**
![image](https://user-images.githubusercontent.com/25671739/190575533-96bf2d14-0bfa-47c3-af18-3a37307c4930.png)

**Technical Details:**
 - Device: Physical Device (Nothing Phone)
 - OS: Windows
Suheb786 commented 2 years ago

getting same issue

mohsinnaqvi606 commented 1 week ago

This error is still reproducible. Any update or solution?