@@ -171,6 +171,9 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
171171 /** @private {shaka.extern.IAdManager} */
172172 this . adManager_ = this . player_ . getAdManager ( ) ;
173173
174+ /** @private {shaka.extern.IQueueManager} */
175+ this . queueManager_ = this . player_ . getQueueManager ( ) ;
176+
174177 /** @private {?shaka.extern.IAd} */
175178 this . ad_ = null ;
176179
@@ -1523,9 +1526,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
15231526 }
15241527 const addMediaSessionHandler = ( type , callback ) => {
15251528 try {
1526- navigator . mediaSession . setActionHandler ( type , ( details ) => {
1527- callback ( details ) ;
1528- } ) ;
1529+ navigator . mediaSession . setActionHandler ( type , callback ) ;
15291530 } catch ( error ) {
15301531 shaka . log . debug (
15311532 `The "${ type } " media session action is not supported.` ) ;
@@ -1607,6 +1608,19 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
16071608 this . togglePiP ( ) ;
16081609 }
16091610 break ;
1611+ case 'nexttrack' :
1612+ this . queueManager_ . playItem (
1613+ this . queueManager_ . getCurrentItemIndex ( ) + 1 ) ;
1614+ break ;
1615+ case 'previoustrack' :
1616+ this . queueManager_ . playItem (
1617+ this . queueManager_ . getCurrentItemIndex ( ) - 1 ) ;
1618+ break ;
1619+ case 'skipad' :
1620+ if ( this . ad_ ) {
1621+ this . ad_ . skip ( ) ;
1622+ }
1623+ break ;
16101624 }
16111625 } ;
16121626
@@ -1725,6 +1739,49 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
17251739 }
17261740 }
17271741 } ) ;
1742+
1743+ const checkQueueItems = ( ) => {
1744+ const itemsLength = this . queueManager_ . getItems ( ) . length ;
1745+ const currentIndex = this . queueManager_ . getCurrentItemIndex ( ) ;
1746+ if ( itemsLength <= 1 || currentIndex == - 1 ) {
1747+ addMediaSessionHandler ( 'previoustrack' , null ) ;
1748+ addMediaSessionHandler ( 'nexttrack' , null ) ;
1749+ return ;
1750+ }
1751+ if ( currentIndex > 0 ) {
1752+ addMediaSessionHandler ( 'previoustrack' , commonHandler ) ;
1753+ } else {
1754+ addMediaSessionHandler ( 'previoustrack' , null ) ;
1755+ }
1756+ if ( ( currentIndex + 1 ) < itemsLength ) {
1757+ addMediaSessionHandler ( 'nexttrack' , commonHandler ) ;
1758+ } else {
1759+ addMediaSessionHandler ( 'nexttrack' , null ) ;
1760+ }
1761+ } ;
1762+
1763+ this . eventManager_ . listen (
1764+ this . queueManager_ , 'currentitemchanged' , checkQueueItems ) ;
1765+ this . eventManager_ . listen (
1766+ this . queueManager_ , 'itemsinserted' , checkQueueItems ) ;
1767+ this . eventManager_ . listen (
1768+ this . queueManager_ , 'itemsremoved' , checkQueueItems ) ;
1769+ this . eventManager_ . listen ( this . player_ , 'loading' , checkQueueItems ) ;
1770+
1771+ const checkSkipAd = ( ) => {
1772+ if ( ! this . ad_ || ! this . ad_ . isSkippable ( ) || ! this . ad_ . canSkipNow ( ) ) {
1773+ addMediaSessionHandler ( 'skipad' , null ) ;
1774+ } else {
1775+ addMediaSessionHandler ( 'skipad' , commonHandler ) ;
1776+ }
1777+ } ;
1778+
1779+ this . eventManager_ . listen (
1780+ this . adManager_ , shaka . ads . Utils . AD_STARTED , checkSkipAd ) ;
1781+ this . eventManager_ . listen (
1782+ this . adManager_ , shaka . ads . Utils . AD_SKIP_STATE_CHANGED , checkSkipAd ) ;
1783+ this . eventManager_ . listen (
1784+ this . adManager_ , shaka . ads . Utils . AD_STOPPED , checkSkipAd ) ;
17281785 }
17291786
17301787
0 commit comments