PageSourceSearch

https://www.johnnycash.com/wp-content/plugins/legacy-streaming-aud…/assets/js/legacy-streaming-audio-player.js

js johnnycash.com collected 2026-09-24 09:18:07 UTC 31,823 bytes, 911 lines download raw bytes

1// AE
2var ae_js;
3var ae_member = '';
4var sme_legacy_player_track_name = '';
5var sme_legacy_player_service_name = '';
6
7function AEJSReady( _aeJS ) {
8	ae_js = _aeJS;
9	ae_js.settings.auth_window = true;
10	ae_js.settings.mobile_detect = false;
11	ae_js.settings.services = 'spotify';
12	ae_js.settings.extra_fields_screen = 'disabled';
13	ae_js.settings['scopes'] = {
14		spotify: 'playlist-modify-private playlist-modify-public playlist-read-collaborative playlist-read-private user-follow-modify user-follow-read user-library-modify user-library-read user-read-email user-read-private user-read-recently-played user-top-read streaming user-modify-playback-state'
15	};
16	ae_js.events.onLogin.addHandler( window.AEJSStreamingAudioPlayerLoginHandler );
17	ae_js.events.onUser.addHandler( window.AEJSStreamingAudioPlayerUserHandler );
18}
19
20
21window.onSpotifyWebPlaybackSDKReady = function () {
22	console.log( 'Spotify Web SDK ready.' );
23};
24
25(
26	function ( $ ) {
27		var global_volume = 100;
28		var global_service = 'none';
29		var save_service = 'none';
30		var global_current_track;
31		var audios = $( '.lsap-track audio' );
32		var spotify_player;
33		var spotify_device_id;
34		var apple_clicked;
35
36		function configSaveModal( button ) {
37			var apple_music_id = button.attr( 'data-apple-id' );
38			var spotify_uri = button.attr( 'data-spotify-uri' );
39
40			$( '#save-popup .save-btns>a' ).hide();
41
42			if ( apple_music_id ) {
43				$( '#save-popup .save-btns>a[data-service="apple_music"]' ).show();
44			}
45
46			if ( spotify_uri ) {
47				$( '#save-popup .save-btns>a[data-service="spotify"]' ).show();
48			}
49
50		}
51
52		function toggleModal( id, action ) {
53			if ( action === 'open' ) {
54				$( 'body' ).addClass( 'legacy-modal-open' );
55				$( id ).show();
56			} else {
57				$( 'body' ).removeClass( 'legacy-modal-open' );
58				$( id ).hide();
59			}
60		}
61
62		function infoModal( apple ) {
63			var info_modal_shown = Cookies.get( 'info_modal_shown' );
64			if ( typeof info_modal_shown === 'undefined' ) {
65				if ( apple ) {
66					toggleModal( '#apple-premium-popup', 'open' );
67				} else {
68					toggleModal( '#spotify-premium-popup', 'open' );
69				}
70
71				Cookies.set( 'info_modal_shown', global_service, { expires: 30 } );
72			}
73		}
74
75		function initSpotifyPlayer( token ) {
76			spotify_player = new Spotify.Player( {
77				name: 'Legacy Spotify Web Player',
78				getOAuthToken: function ( cb ) {
79					cb( token );
80				}
81			} );
82
83			// Error handling
84			spotify_player.addListener( 'initialization_error', function ( message ) {
85				console.error( message );
86				toggleModal( '#spotify-free-popup', 'open' );
87			} );
88			spotify_player.addListener( 'authentication_error', function ( message ) {
89				console.error( message );
90			} );
91			spotify_player.addListener( 'account_error', function ( message ) {
92				console.error( message );
93			} );
94			spotify_player.addListener( 'playback_error', function ( message ) {
95				console.error( message );
96			} );
97
98			// Playback status updates
99			spotify_player.addListener( 'player_state_changed', function ( state ) {
100				console.log( state );
101			} );
102
103			// Ready
104			spotify_player.addListener( 'ready', function ( device ) {
105				spotify_device_id = device.device_id;
106				console.log( 'Ready with Device ID', device.device_id );
107				infoModal();
108			} );
109
110			// Not Ready
111			spotify_player.addListener( 'not_ready', function ( device ) {
112				console.log( 'Device ID has gone offline', device.device_id );
113			} );
114
115			// Connect to the player!
116			spotify_player.connect();
117
118			setInterval( function () {
119				if ( $( '.legacy-streaming-audio-player.active' ).length > 0 ) {
120					spotify_player.getCurrentState().then( function ( state ) {
121						if ( state !== null ) {
122							var progress = $( '.legacy-streaming-audio-player.active .lsap-progress' );
123							progress.find( '.lsap-progress-duration-current' ).text( formatTime( state.position / 1000 ) );
124							progress.find( '.lsap-progress-bar>div' ).css( 'width', (
125								                                                        state.position / 1000
126							                                                        ) / (
127								                                                        state.duration / 1000
128							                                                        ) * 100 + '%' );
129							global_current_track.find( '.lsap-track-progress' ).css( 'width', (
130								                                                                  state.position / 1000
131							                                                                  ) / (
132								                                                                  state.duration / 1000
133							                                                                  ) * 100 + '%' );
134						}
135					}
135 ).catch( onPromiseError );
136				}
137			}, 1000 );
138		}
139
140		// Musickit
141		MusicKit.configure( {
142			developerToken: lsap_wp.apple_music_jwt,
143			app: {
144				name: 'Sony Music Entertainment',
145				icon: 'https://cdn.smehost.net/formssonymusicfanscom-appirioprod/wp-content/uploads/2018/10/Sony_Music_logo_logotype3.png'
146			}
147		} );
148
149		var apple_music = MusicKit.getInstance();
150
151		// Load if previous player
152		var service = getPlayerCookie();
153		if ( service === 'apple_music' ) {
154			if ( apple_music.isAuthorized === true ) {
155				infoModal( true );
156				setActivePlayer( service );
157			}
158		}
159
160		// Spotify
161		var spotify_api = new SpotifyWebApi();
162
163		// Promise Error Handler
164		function onPromiseError( ex ) {
165			console.log( 'global service: ' + global_service );
166			console.log( 'error message:' );
167			console.log( ex );
168
169			// Spotify premium alert
170			if ( typeof ex.responseText !== 'undefined' ) {
171				if ( ex.responseText.includes( 'PREMIUM_REQUIRED' ) ) {
172					toggleModal( '#spotify-free-popup', 'open' );
173				}
174			}
175		}
176
177		// AE Login Handler
178		function AEJSStreamingAudioPlayerLoginHandler( user, type, sso ) {
179			ae_member = user;
180			SMFOptIn( user, null, null, lsap_wp.smf.ae_activities_default );
181
182			for ( var s = 0; s < user.services.length; s ++ ) {
183				if ( user.services[s].Service === 'spotify' ) {
184					if ( typeof Spotify !== 'undefined' ) {
185						spotify_api.setAccessToken( user.services[s].Token );
186						initSpotifyPlayer( user.services[s].Token );
187						var is_firefox = navigator.userAgent.toLowerCase().indexOf( 'firefox' ) > - 1;
188						var is_android = navigator.platform.toLowerCase().indexOf( 'android' ) > - 1;
189
190						if ( is_firefox && is_android ) {
191							toggleModal( '#spotify-free-popup', 'open' );
192						}
193					} else {
194						alert( 'The Spotify API has not yet loaded. Please try again in a few moments.' );
195					}
196					break;
197				}
198			}
199			$( '.legacy-streaming-audio-player' ).removeClass( 'lsap-logged-out' ).addClass( 'lsap-logged-in' );
200		}
201
202		window.AEJSStreamingAudioPlayerLoginHandler = AEJSStreamingAudioPlayerLoginHandler;
203
204		// AE User Handler
205		function AEJSStreamingAudioPlayerUserHandler( user, state ) {
206			if ( state === 'init' ) {
207				ae_member = user;
208				SMFOptIn( user, null, null, lsap_wp.smf.ae_activities_default );
209				var service = getPlayerCookie();
210				for ( var s = 0; s < user.services.length; s ++ ) {
211					if ( user.services[s].Service === 'spotify' ) {
212						if ( service === 'spotify' ) {
213							$.ajax( {
214								url: lsap_wp.ajax_url,
215								method: 'POST',
216								dataType: 'json',
217								data: {
218									action: 'ae_refresh_spotify_token',
219									security: lsap_wp.spotify_nonce,
220									ae_service_id: user.services[s].ID
221								},
222								error: function () {
223									alert( 'Error refreshing Spotify tokens!' );
224								},
225								success: function ( response ) {
226									if ( response.success ) {
227										var spotify_loaded = setInterval( function () {
228											if ( typeof Spotify !== 'undefined' ) {
229												var ae_data = JSON.parse( response.data );
230												spotify_api.setAccessToken( ae_data.AccessToken );
231												initSpotifyPlayer( ae_data.AccessToken );
232												setActivePlayer( service );
233												clearInterval( spotify_loaded );
234											}
235										}, 1000 );
236									} else {
237										alert( 'Error refreshing Spotify tokens!' );
238									}
239								}
240							} );
241						}
242						break;
243					}
244				}
245			}
246		}
247
248		window.AEJSStreamingAudioPlayerUserHandler = AEJSStreamingAudioPlayerUserHandler;
249
250		function SMFOptIn( user, apple_token, apple_email, ae_activities ) {
251			var data = {
252				field_email_address: typeof user !== 'undefined' && user !== null ? user.data.Email : apple_email,
253				field_first_name: typeof user !== 'undefined' && user !== null ? user.data.FirstName : '',
254				field_last_name: typeof user !== 'undefined' && user !== null ? user.data.Surname : '',
255				ae: lsap_wp.smf.ae,
256				ae_member_id: typeof user !== 'undefined' && user !== null ? user.data.ID : '',
257				ae_brand_id: lsap_wp.smf.ae_brand_id,
258				ae_segment_id: lsap_wp.smf.ae_segment_id,
259				ae_activities: ae_activities,
260				form: lsap_wp.smf.form_id,
261				default_mailing_list: lsap_wp.smf.default_mailing_list
262			};
263
264			if ( typeof apple_token !== 'undefined' && apple_token !== null ) {
265				data.am_music_user_token = apple_token;
266			}
267
268			$.ajax( {
269				url: 'https://subs.sonymusicfans.com/submit',
270				method: 'POST',
271				dataType: 'json',
272				data: data,
273				xhrFields: {
274					withCredentials: false
275				},
276				error: function () {
277					console.log( 'SMF form submission error' );
278				},
279				success: function () {
280					console.log( 'SMF form submission successful' );
281				}
282			} );
283		}
284
285		// Format Time
286		function formatTime( time ) {
287			if ( !Number.isNaN( time ) ) {
288				return new Date( time * 1000 ).toISOString().substr( 11, 8 ).substr( 3 );
289			} else {
290				return '0:00';
291			}
292		}
293
294		// Stop other players when switching services
295		function stopOtherPlayers() {
296			switch ( global_service ) {
297				case 'apple_music':
298					audios.trigger( 'pause' );
299					if ( typeof spotify_player !== 'undefined' ) {
300						spotify_player.pause().then().catch( onPromiseError );
301					}
302					break;
303				case 'spotify':
304					apple_music.player.pause();
305					audios.trigger( 'pause' );
306					break;
307				case 'none':
308					apple_music.player.pause();
309					if ( typeof spotify_player !== 'undefined' ) {
310						spotify_player.pause().then().catch( onPromiseError );
311					}
312				default:
313					break;
314			}
315		}
316
317		// Check if a service is authorized
318		function isAuthed( service ) {
319			var promise = new Promise( function ( resolve, reject ) {
320				var timer;
321				var iterations = 30;
322				switch ( service ) {
323					case 'apple_music':
324						sme_legacy_player_service_name = 'apple_music';
325						break;
326					case 'spotify':
327						sme_legacy_player_service_name = 'spotify';
328						if ( spotify_api.getAccessToken() !== null ) {
329							global_service = 'spotify';
330							save_service = 'spotify';
331							resolve( true );
332						} else {
333							ae_js.trigger.authenticate( 'spotify', 'register' );
334							timer = setInterval( function () {
335								if ( iterations > 60 ) {
336									clearInterval( timer );
337									reject( 'Timed Out' );
338								}
339								if ( spotify_api.getAccessToken() !== null ) {
340									clearInterval( timer );
341									global_service = 'spotify';
342									save_service = 'spotify';
343									resolve( true );
344								}
345							}, 1000 );
346						}
347					/*default:
348						console.log( 'resolved at bottom?' );
349						resolve( true );
350						break;*/
351				}
352			} );
353			return promise;
354		}
355
356		function getPlayerCookie() {
357			var service = Cookies.get( 'legacy_player_selected' );
358
359			if ( typeof service === 'undefined' ) {
360				service = 'none';
361			}
362
363			return service;
364		}
365
366		function setPlayerCookie() {
367			Cookies.set( 'legacy_player_selected', global_service, { expires: 30 } );
368		}
369
370		// Set Track Duration Info
371		function updateTrackDurations() {
372			$( '.legacy-streaming-audio-player' ).each( function () {
373				var self = $( this );
374				var tracks = $( this ).find( '.lsap-track' );
375				var now_playing_title = $( this ).find( '.lsap-now-playing-title' ).text();
376
377				tracks.each( function () {
378					var audio_duration = $( this ).attr( 'data-duration' );
379					var title = $( this ).attr( 'data-title' );
380					var audio_el_duration = formatTime( $( this ).find( 'audio' )[0].duration );
381					if ( global_service === 'none' /*&& audio_el_duration !== '0:00'*/ ) {
382						//audio_duration = audio_el_duration;
383						audio_duration = '00:30';
384					}
385					$( this ).find( '.lsap-track-duration' ).text( audio_duration );
386					if ( now_playing_title === title ) {
387						self.find( '.lsap-progress-duration-total' ).text( audio_duration );
388					}
389				} );
390			} );
391		}
392
393		function setActivePlayer( service ) {
394			global_service = service;
395			sme_legacy_player_service_name = global_service;
396			$( '.lsap-stream-service-selection>ul>li>button' ).removeClass( 'active' );
397			$( '.lsap-stream-service-selection>ul>li>button[data-service=' + service + ']' ).addClass( 'active' );
398			updateTrackDurations();
399			$( '.legacy-streaming-audio-player' ).removeClass( 'lsap-logged-out' ).addClass( 'lsap-logged-in' );
400		}
401
402		function StreamingAudioPlayer( element, options ) {
403			var $element = $( element );
404			var all_elements = $( '.legacy-streaming-audio-player' );
405			var local_audios = $element.find( '.lsap-track audio' );
406			var play_pause_button = $element.find( '.lsap-play-progress .lsap-play-controls .lsap-play-controls-play-pause' );
407			var progress = $element.find( '.lsap-progress' );
408			var volume_bars = $( '.lsap-volume-control-bar>div' );
409			var all_tracks = $( '.lsap-track' );
410			var last_playing = $element.find( '.lsap-track:nth-child(2)' );
411
412			updatePlayerInfo();
413			updateTrackDurations();
414
415			// Update Player Info
416			function updatePlayerInfo( track ) {
417
418				var track = typeof track !== 'undefined' && track !== null ? track : last_playing;
419
420				// Update player info
421				$element.find( '.lsap-now-playing-artist' ).text( track.attr( 'data-artist' ) );
422				$element.find( '.lsap-now-playing-title' ).text( track.attr( 'data-title' ) );
423
424				if ( global_service === 'none' ) {
425					var audio_duration = formatTime( $element.find( 'audio' )[0].duration );
426					$element.find( '.lsap-progress-duration-total' ).text( audio_duration );
427				} else {
428					$element.find( '.lsap-progress-duration-total' ).text( track.attr( 'data-duration' ) );
429				}
430
431				var artwork = $element.find( '.lsap-artwork' );
432				var image = track.attr( 'data-image' );
433
434				if ( image !== '' ) {
435					artwork.html( '<img src="' + image + '" alt="' + track.attr( 'data-title' ) + '" />' );
436				} else {
437					artwork.empty();
438				}
439			}
440
441			// Toggle play/pause button icon
442			function togglePlayButton( el, state ) {
443				all_tracks.each( function () {
444					$( this ).find( 'i:nth-child(1)' ).show();
445					$( this ).find( 'i:nth-child(2)' ).hide();
446				} );
447				if ( state === 'play' ) {
448					el.find( 'i:nth-child(1)' ).hide();
449					el.find( 'i:nth-child(2)' ).show();
450					play_pause_button.find( 'i:nth-child(1)' ).hide();
451					play_pause_button.find( 'i:nth-child(2)' ).show();
452				} else {
453					el.find( 'i:nth-child(1)' ).show();
454					el.find( 'i:nth-child(2)' ).hide();
455					play_pause_button.find( 'i:nth-child(1)' ).show();
456					play_pause_button.find( 'i:nth-child(2)' ).hide();
457				}
458			}
459
460			// Show stream service popup
461			function showStreamCTAPopup( el ) {
462				var top = el.position().top;
463				var popup = $element.find( '.lsap-stream-popup' );
464
465				console.log( $( el ).attr( 'data-apple-id' ) );
466
467				if ( $( el ).attr( 'data-apple-id' ) ) {
468					popup.find( '.lsap-stream-service-selection>ul>li:first-child' ).show();
469				} else {
470					popup.find( '.lsap-stream-service-selection>ul>li:first-child' ).hide();
471				}
472
473				if ( $( el ).attr( 'data-spotify-uri' ) ) {
474					popup.find( '.lsap-stream-service-selection>ul>li:last-child' ).show();
475				} else {
476					popup.find( '.lsap-stream-service-selection>ul>li:last-child' ).hide();
477				}
478
479				popup.css( 'top', top - popup.outerHeight() + 10 ).fadeIn();
480				setTimeout( function () {
481					popup.fadeOut();
482				}, 8000 );
483			}
484
485			// Login Service Buttons
486			$element.find( '.lsap-stream-service-selection>ul>li>button' ).on( 'click', function ( e ) {
487				e.preventDefault();
488				var service = $( this ).attr( 'data-service' );
489				$( '.lsap-stream-service-selection>ul>li>button' ).removeClass( 'active' );
490				$( '.lsap-stream-service-selection>ul>li>button[data-service=' + service + ']' ).addClass( 'active' );
491
492				if ( service === 'apple_music' ) {
493					sme_legacy_player_service_name = 'apple_music';
494					var apple_email = Cookies.get( 'legacy_player_apple_email' );
495					if ( typeof apple_email === 'undefined' || apple_email === '' || apple_email === null ) {
496						toggleModal( '#apple-music-popup', 'open' );
497						apple_clicked = $element;
498					} else {
499						apple_music.authorize().then( function () {
500							infoModal( true );
501							SMFOptIn( null, apple_music.musicUserToken, apple_email, lsap_wp.smf.ae_activities_default );
502							var apple_music_id = last_playing.attr( 'data-apple-id' );
503							apple_music.api.song( apple_music_id ).then( function ( song ) {
504								apple_music.setQueue( { url: song.attributes.url } ).then( function ( queue ) {
505								} );
506							} );
507							global_service = 'apple_music';
508							save_service = 'apple_music';
509							updateTrackDurations();
510							setPlayerCookie();
511						} );
512					}
513				} else {
514					isAuthed( service ).then( function () {
515						console.log( 'global service: ' + global_service );
516						console.log( 'authenticated' );
517						updateTrackDurations();
518						setPlayerCookie();
519					} ).catch( onPromiseError );
520				}
521			} );
522
523			// Play / Pause
524			play_pause_button.on( 'click', function ( e ) {
525				e.preventDefault();
526				last_playing.find( '.lsap-track-controls .lsap-track-controls-play-pause' ).trigger( 'click' );
527				global_current_track = last_playing;
528			} );
529
530			// Prev
531			$element.find( '.lsap-play-progress .lsap-play-controls .lsap-play-controls-prev' ).on( 'click', function ( e ) {
532				e.preventDefault();
533				var prev_track = last_playing.prev( '.lsap-track' );
534				if ( prev_track.length === 0 ) {
535					prev_track = last_playing.siblings( '.lsap-track' ).last();
536				}
537				prev_track.find( '.lsap-track-controls .lsap-track-controls-play-pause' ).trigger( 'click' );
538				global_current_track = prev_track;
539			} );
540
541			// Next
542			$element.find( '.lsap-play-progress .lsap-play-controls .lsap-play-controls-next' ).on( 'click', function ( e ) {
543				e.preventDefault();
544				var next_track = last_playing.next( '.lsap-track' );
545				if ( next_track.length === 0 ) {
546					next_track = last_playing.siblings( '.lsap-track' ).first();
547				}
548				next_track.find( '.lsap-track-controls .lsap-track-controls-play-pause' ).trigger( 'click' );
549				global_current_track = next_track;
550			} );
551
552			// Mute
553			$element.find( '.lsap-info-volume .lsap-volume-controls .lsap-volume-control-mute' ).on( 'click', function ( e ) {
554				e.preventDefault();
555				global_volume = 0;
556				volume_bars.css( 'width', '0%' );
557				audios.prop( 'volume', 0 );
558				apple_music.player.mute();
559				if ( typeof spotify_player !== 'undefined' ) {
560					spotify_player.setVolume( 0 ).then().catch( onPromiseError );
561				}
562			} );
563
564			// Volume Bar
565			$element.find( '.lsap-volume-control-bar' ).on( 'click', function ( e ) {
566				e.preventDefault();
567				var click_width = e.pageX - $( this ).position().left;
568				var per = (
569					click_width / $( this ).width()
570				);
571				var rounded_per = Math.round( per * 100 ) / 100;
572
573				if ( rounded_per > 1 ) {
574					rounded_per = 1;
575				} else if ( rounded_per < 0 ) {
576					rounded_per = 0;
577				}
578				volume_bars.css( 'width', rounded_per * 100 + '%' );
579				audios.prop( 'volume', rounded_per );
580				apple_music.player.volume = rounded_per;
581				if ( typeof spotify_player !== 'undefined' ) {
582					spotify_player.setVolume( rounded_per ).then().catch( onPromiseError );
583				}
584			} );
585
586			// Maximum Volume
587			$element.find( '.lsap-info-volume .lsap-volume-controls .lsap-volume-control-max' ).on( 'click', function ( e ) {
588				e.preventDefault();
589				global_volume = 100;
590				volume_bars.css( 'width', '100%' );
591				audios.prop( 'volume', global_volume / 100 );
592				apple_music.player.volume = 1;
593				if ( typeof spotify_player !== 'undefined' ) {
594					spotify_player.setVolume( 1 ).then().catch( onPromiseError );
595				}
596			} );
597
598			// Track Play / Pause
599			$element.find( '.lsap-tracks .lsap-track .lsap-track-controls .lsap-track-controls-play-pause' ).on( 'click', function ( e ) {
600				e.preventDefault();
601				all_elements.removeClass( 'active' );
602				$element.addClass( 'active' );
603				var track = $( this ).parents( '.lsap-track' );
604				var self = $( this );
605
606				updatePlayerInfo( track );
607				sme_legacy_player_track_name = track.attr( 'data-title' );
608				// Stop other players
609				stopOtherPlayers();
610				switch ( global_service ) {
611					case 'apple_music':
612						sme_legacy_player_service_name = 'apple_music';
613						var apple_music_id = track.attr( 'data-apple-id' );
614						if ( apple_music_id ) {
615							apple_music.authorize().then( function () {
616								infoModal( true );
617								// Progress - not sure why this only works here
618								apple_music.addEventListener( MusicKit.Events.playbackProgressDidChange, function ( event ) {
619									var progress = $( '.legacy-streaming-audio-player.active .lsap-progress' );
620									progress.find( '.lsap-progress-duration-current' ).text( formatTime( apple_music.player.currentPlaybackTime ) );
621									progress.find( '.lsap-progress-bar>div' ).css( 'width', event.progress * 100 + '%' );
622									global_current_track.find( '.lsap-track-progress' ).css( 'width', event.progress * 100 + '%' );
623								} );
624								if ( track[0] === last_playing[0] && !apple_music.player.queue.isEmpty ) {
625									if ( !apple_music.player.isPlaying ) {
626										apple_music.player.play();
627										togglePlayButton( self, 'play' );
628									} else {
629										apple_music.player.pause();
630										togglePlayButton( self, 'pause' );
631									}
632								} else {
633									apple_music.api.song( apple_music_id ).then( function ( song ) {
634										apple_music.setQueue( { url: song.attributes.url } ).then( function ( queue ) {
635											apple_music.player.play();
636											togglePlayButton( self, 'play' );
637										} );
638									} );
639								}
640								global_service = 'apple_music';
641								save_service = 'apple_music';
642								last_playing = track;
643							} );
644						}
645						break;
646					case 'spotify':
647						sme_legacy_player_service_name = 'spotify';
648						var spotify_uri = track.attr( 'data-spotify-uri' );
649						if ( spotify_uri ) {
650							isAuthed( 'spotify' ).then( function () {
651								spotify_player.getCurrentState().then( function ( state ) {
652									if ( state === null || state.track_window.current_track.uri !== spotify_uri ) {
653										spotify_api.play( {
654											device_id: spotify_device_id,
655											uris: [spotify_uri]
656										} ).then( function () {
657											togglePlayButton( self, 'play' );
658											last_playing = track;
659										}
659 ).catch( onPromiseError );
660									} else if ( state.paused === false ) {
661										spotify_player.pause().then( function () {
662											togglePlayButton( self, 'pause' );
663										} ).catch( onPromiseError );
664									} else {
665										spotify_player.resume().then( function () {
666											togglePlayButton( self, 'play' );
667										} ).catch( onPromiseError );
668									}
669								} ).catch( onPromiseError );
670							} ).catch( onPromiseError );
671						}
672						break;
673					default:
674					case 'none':
675						var track_audio = track.find( 'audio' );
676						if ( track_audio[0].paused ) {
677							audios.trigger( 'pause' );
678							track_audio[0].play();
679							togglePlayButton( self, 'play' );
680							showStreamCTAPopup( track );
681						} else {
682							track_audio[0].pause();
683							togglePlayButton( self, 'pause' );
684						}
685						last_playing = track;
686						break;
687				}
688				global_current_track = track;
689			} );
690
691			// Progress Bar
692			local_audios.bind( 'timeupdate', function () {
693				var audio_el = $( this )[0];
694				progress.find( '.lsap-progress-duration-current' ).text( formatTime( audio_el.currentTime ) );
695				progress.find( '.lsap-progress-bar>div' ).css( 'width', audio_el.currentTime / audio_el.duration * 100 + '%' );
696				global_current_track.find( '.lsap-track-progress' ).css( 'width', audio_el.currentTime / audio_el.duration * 100 + '%' );
697			} );
698		}
699
700		$.fn.streamingAudioPlayer = function ( options ) {
701			return this.each( function () {
702				new StreamingAudioPlayer( this );
703			} );
704		};
705
706		$( document ).ready( function () {
707			$( '.legacy-streaming-audio-player' ).streamingAudioPlayer();
708
709			$( '.lsap-popup' ).on( 'click', function ( e ) {
710				e.preventDefault();
711				var href = $( this ).attr( 'href' );
712				var h = 475;
713				var w = 500;
714				var y = window.top.outerHeight / 2 + window.top.screenY - (
715					h / 2
716				);
717				var x = window.top.outerWidth / 2 + window.top.screenX - (
718					w / 2
719				);
720				return window.open( href, 'Legacy Streaming Audio Player', `toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${w}, height=${h}, top=${y}, left=${x}` );
721			} );
722
723			$( '#apple-music-popup-close' ).on( 'click', function ( e ) {
724				e.preventDefault();
725				toggleModal( '#apple-music-popup', 'close' );
726			} );
727
728			$( '#save-close' ).on( 'click', function ( e ) {
729				e.preventDefault();
730				toggleModal( '#save-popup', 'close' );
731			} );
732
733			$( '#spotify-free-popup-close' ).on( 'click', function ( e ) {
734				e.preventDefault();
735				toggleModal( '#spotify-free-popup', 'close' );
736			} );
737
738			$( '#spotify-premium-popup-close' ).on( 'click', function ( e ) {
739				e.preventDefault();
740				toggleModal( '#spotify-premium-popup', 'close' );
741			} );
742
743			$( '#apple-premium-popup-close' ).on( 'click', function ( e ) {
744				e.preventDefault();
745				toggleModal( '#apple-premium-popup', 'close' );
746			} );
747
748			$( '#apple-music-form' ).on( 'submit', function ( e ) {
749				e.preventDefault();
750				var apple_email = $( '#apple_email_address' ).val();
751				if ( apple_email ) {
752					Cookies.set( 'legacy_player_apple_email', apple_email, { expires: 30 } );
753					toggleModal( '#apple-music-popup', 'close' );
754					if ( save_ele_clicked === null ) {
755						apple_clicked.find( '.lsap-stream-service-selection>ul>li>button[data-service="apple_music"]' ).trigger( 'click' );
756					} else {
757						$( '#save-popup .save-btns>a[data-service="apple_music"]' ).trigger( 'click' );
758					}
759				}
760			} );
761
762			var save_ele_clicked = null;
763			$( '#save-popup .save-btns>a' ).on( 'click', function ( e ) {
764				e.preventDefault();
765				var service = $( this ).attr( 'data-service' );
766				save_service = service;
767				switch ( service ) {
768					case 'apple_music':
769						var apple_email = Cookies.get( 'legacy_player_apple_email' );
770						if ( typeof apple_email === 'undefined' || apple_email === '' || apple_email === null ) {
771							toggleModal( '#apple-music-popup', 'open' );
772						} else {
773							/*apple_music.authorize().then( function () {
774								SMFOptIn( null, apple_music.musicUserToken, apple_email, lsap_wp.smf.ae_activities_default );
775								global_service = 'apple_music';
776								save_service = 'apple_music';
777								updateTrackDurations();
778								setPlayerCookie();
779								save_ele_clicked.trigger( 'click' );
780							} );*/
781							save_ele_clicked.trigger( 'click' );
782						}
783						break;
784					default:
785						isAuthed( service ).then( function () {
786							save_ele_clicked.trigger( 'click' );
787						}
787 ).catch( onPromiseError );
788						break;
789				}
790				toggleModal( '#save-popup', 'close' );
791			} );
792
793			$( '.lsap-track-save, .lsap-tracks .lsap-track .lsap-library-add' ).on( 'click', function ( e ) {
794				e.preventDefault();
795				sme_legacy_player_track_name = $( this ).parents( '.lsap-track' ).attr( 'data-title' );
796				if ( save_service === 'none' ) {
797					configSaveModal( $( this ) );
798					toggleModal( '#save-popup', 'open' );
799					save_ele_clicked = $( this );
800				} else {
801					save_ele_clicked = null;
802					switch ( save_service ) {
803						case 'none':
804							alert( 'Please sign into a service.' );
805							break;
806						case 'apple_music':
807							sme_legacy_player_service_name = 'apple_music';
808							if ( $( this ).hasClass( 'lsap-library-add' ) ) {
809								var apple_music_id = $( this ).parents( '.lsap-track' ).attr( 'data-apple-id' );
810							} else {
811								var apple_music_id = $( this ).attr( 'data-apple-id' );
812							}
813							if ( apple_music_id && apple_music_id !== '' ) {
814								apple_music.authorize().then( function () {
815									infoModal( true );
816									apple_music.api.addToLibrary( {
817										albums: [apple_music_id]
818									} ).then( function () {
819										var apple_email = Cookies.get( 'legacy_player_apple_email' );
820										SMFOptIn( null, apple_music.musicUserToken, apple_email, lsap_wp.smf.ae_activities_apple_music_save_track );
821										alert( 'Track saved!' );
822									} ).catch( onPromiseError );
823								} ).catch( onPromiseError );
824							} else {
825								alert( 'Unable to save - Apple Music ID is missing for this content.' );
826							}
827							break;
828						case 'spotify':
829							sme_legacy_player_service_name = 'spotify';
830							if ( $( this ).hasClass( 'lsap-library-add' ) ) {
831								var spotify_uri = $( this ).parents( '.lsap-track' ).attr( 'data-spotify-uri' );
832							} else {
833								var spotify_uri = $( this ).attr( 'data-spotify-uri' );
834							}
835
836							if ( spotify_uri && spotify_uri !== '' ) {
837								isAuthed( 'spotify' ).then( function () {
838									spotify_api.addToMySavedTracks( [spotify_uri.replace( 'spotify:track:', '' )] ).then( function () {
839										SMFOptIn( ae_member, null, null, lsap_wp.smf.ae_activities_spotify_save_track );
840										alert( 'Track saved!' );
841									} ).catch( onPromiseError );
842								} ).catch( onPromiseError );
843							} else {
844								alert( 'Unable to save - Spotify ID is missing for this content.' );
845							}
846							break;
847						case 'none':
848						default:
849							break;
850					}
851				}
852			} );
853
854			$( '.lsap-album-save' ).on( 'click', function ( e ) {
855				e.preventDefault();
856
857				if ( save_service === 'none' ) {
858					configSaveModal( $( this ) );
859					toggleModal( '#save-popup', 'open' );
860					save_ele_clicked = $( this );
861				} else {
862					save_ele_clicked = null;
863					switch ( save_service ) {
864						case 'none':
865							alert( 'Please sign into a service.' );
866							break;
867						case 'apple_music':
868							var apple_music_id = $( this ).attr( 'data-apple-id' );
869							if ( apple_music_id && apple_music_id !== '' ) {
870								apple_music.authorize().then( function () {
871									infoModal( true );
872									apple_music.api.addToLibrary( {
873										albums: [apple_music_id]
874									} ).then( function () {
875										var apple_email = Cookies.get( 'legacy_player_apple_email' );
876										SMFOptIn( null, apple_music.musicUserToken, apple_email, lsap_wp.smf.ae_activities_apple_music_save_album );
877										alert( 'Album saved!' );
878									} ).catch( onPromiseError );
879								} ).catch( onPromiseError );
880							} else {
881								alert( 'Unable to save - Apple Music ID is missing for this content.' );
882							}
883							break;
884						case 'spotify':
885							var spotify_uri = $( this ).attr( 'data-spotify-uri' );
886							if ( spotify_uri && spotify_uri !== '' ) {
887								isAuthed( 'spotify' ).then( function () {
888									spotify_api.addToMySavedAlbums( [spotify_uri.replace( 'spotify:album:', '' )] ).then( function () {
889										SMFOptIn( ae_member, null, null, lsap_wp.smf.ae_activities_spotify_save_album );
890										alert( 'Album saved!' );
891									}
891 ).catch( onPromiseError );
892								} ).catch( onPromiseError );
893							} else {
894								alert( 'Unable to save - Spotify ID is missing for this content.' );
895							}
896							break;
897						case 'none':
898						default:
899							break;
900					}
901				}
902			} );
903		} );
904
905		// ADA
906		$( window ).load(function() {
907			$( 'iframe[src*="https://sdk.scdn.co/embedded/index.html"]' ).attr( 'tabindex', '-1' ).attr( 'aria-hidden', 'true' );
908		});
909	}
910)
911( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.