@@ -10,8 +10,8 @@ import {
1010} from "../../utils/utils" ;
1111import { DataSourceProps , DataSourceType } from "./BrainzPlayer" ;
1212import GlobalAppContext from "../../utils/GlobalAppContext" ;
13- import { BrainzPlayerContext } from "./BrainzPlayerContext" ;
1413import { dataSourcesInfo } from "../../settings/brainzplayer/BrainzPlayerSettings" ;
14+ import { currentDataSourceNameAtom , store } from "./BrainzPlayerAtoms" ;
1515
1616export type AppleMusicPlayerProps = DataSourceProps ;
1717
@@ -149,20 +149,20 @@ export default class AppleMusicPlayer
149149 }
150150
151151 componentDidUpdate ( prevProps : DataSourceProps ) {
152- const { show, volume } = this . props ;
153- const player = this . appleMusicPlayer ;
154- if ( prevProps . volume !== volume && player ) {
155- player . volume = ( volume ?? 100 ) / 100 ;
156- }
157- if ( prevProps . show && ! show ) {
158- this . stopAndClear ( ) ;
152+ const { volume } = this . props ;
153+ if ( this . appleMusicPlayer && prevProps . volume !== volume ) {
154+ this . appleMusicPlayer . volume = ( volume ?? 100 ) / 100 ;
159155 }
160156 }
161157
162158 componentWillUnmount ( ) : void {
163159 this . disconnectAppleMusicPlayer ( ) ;
164160 }
165161
162+ stop = ( ) => {
163+ this . appleMusicPlayer ?. pause ( ) ;
164+ } ;
165+
166166 playAppleMusicId = async (
167167 appleMusicId : string ,
168168 retryCount = 0
@@ -260,8 +260,9 @@ export default class AppleMusicPlayer
260260 } ;
261261
262262 playListen = async ( listen : Listen | JSPFTrack ) : Promise < void > => {
263- const { show } = this . props ;
264- if ( ! show ) {
263+ const isCurrentDataSource =
264+ store . get ( currentDataSourceNameAtom ) === this . name ;
265+ if ( ! isCurrentDataSource ) {
265266 return ;
266267 }
267268 const apple_music_id = AppleMusicPlayer . getURLFromListen ( listen as Listen ) ;
@@ -471,8 +472,9 @@ export default class AppleMusicPlayer
471472 } ;
472473
473474 render ( ) {
474- const { show } = this . props ;
475- if ( ! show ) {
475+ const isCurrentDataSource =
476+ store . get ( currentDataSourceNameAtom ) === this . name ;
477+ if ( ! isCurrentDataSource ) {
476478 return null ;
477479 }
478480 return < div > { this . getAlbumArt ( ) } </ div > ;
0 commit comments