13

If you have two browser tabs open to a Soundcloud page, or a page with a Soundcloud iFrame, with one tab playing, when you press play in the other tab it will pause the first. Howe exactly is this achieved?

Zack
  • 657
  • 5
  • 16

1 Answers1

23

It uses local storage to achieve this. It stores JSON data of all the songs that have played or been paused in each of your tabs. As soon as you play another song, all of the other songs' playing statuses are set to paused inside local storage. Most likely, a localStorage event is triggered which checks which songs need to be paused and pauses them.

Soundcloud local storage viewed in Chrome

danronmoon
  • 3,814
  • 5
  • 34
  • 56
  • 3
    Whoa, `localStorage` updates immediately between multiple tabs and broadcasts events? I suppose that makes sense, just never thought about that scenario. Neat. – Alex Wayne Jan 30 '14 at 01:22
  • 3
    @AlexWayne also works for cookies too. Well, not the broadcast events part. Combined with a `setInterval` or the like, it could be used as a fallback for legacy browsers in this case. – danronmoon Jan 30 '14 at 01:29