@@ -98,8 +98,8 @@ shaka.ui.PipButton = class extends shaka.ui.Element {
9898 this . onLeavePictureInPicture_ ( ) ;
9999 } ) ;
100100
101- this . eventManager . listen ( this . controls , 'caststatuschanged' , ( e ) => {
102- this . onCastStatusChange_ ( e ) ;
101+ this . eventManager . listen ( this . controls , 'caststatuschanged' , ( ) => {
102+ this . onTracksChanged_ ( ) ;
103103 } ) ;
104104
105105 this . eventManager . listen ( this . player , 'trackschanged' , ( ) => {
@@ -164,25 +164,6 @@ shaka.ui.PipButton = class extends shaka.ui.Element {
164164 this . localization . resolve ( currentPipState ) ;
165165 }
166166
167- /**
168- * @param {Event } e
169- * @private
170- */
171- onCastStatusChange_ ( e ) {
172- const isCasting = e [ 'newStatus' ] ;
173-
174- if ( isCasting ) {
175- // Picture-in-picture is not applicable if we're casting
176- if ( this . controls . isPiPAllowed ( ) ) {
177- shaka . ui . Utils . setDisplay ( this . pipButton_ , false ) ;
178- }
179- } else {
180- if ( this . controls . isPiPAllowed ( ) ) {
181- shaka . ui . Utils . setDisplay ( this . pipButton_ , true ) ;
182- }
183- }
184- }
185-
186167
187168 /**
188169 * Display the picture-in-picture button only when the content contains video.
@@ -194,6 +175,9 @@ shaka.ui.PipButton = class extends shaka.ui.Element {
194175 async onTracksChanged_ ( ) {
195176 if ( ! this . controls . isPiPAllowed ( ) ) {
196177 shaka . ui . Utils . setDisplay ( this . pipButton_ , false ) ;
178+ if ( this . controls . isPiPEnabled ( ) ) {
179+ await this . controls . togglePiP ( ) ;
180+ }
197181 } else if ( this . player && this . player . isAudioOnly ( ) ) {
198182 shaka . ui . Utils . setDisplay ( this . pipButton_ , false ) ;
199183 if ( this . controls . isPiPEnabled ( ) ) {
0 commit comments