webamp 0.0.0-next-a180155 → 0.0.0-next-f4daf82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13777,6 +13777,57 @@
13777
13777
  }
13778
13778
  }
13779
13779
 
13780
+ function enableMediaSession(webamp) {
13781
+ if ("mediaSession" in navigator) {
13782
+ /* global MediaMetadata */
13783
+ webamp.onTrackDidChange((track) => {
13784
+ if (track == null) {
13785
+ return;
13786
+ }
13787
+ const { metaData: { title, artist, album, albumArtUrl }, } = track;
13788
+ navigator.mediaSession.metadata = new MediaMetadata({
13789
+ title: title ?? undefined,
13790
+ artist: artist ?? undefined,
13791
+ album: album ?? undefined,
13792
+ artwork: albumArtUrl
13793
+ ? [
13794
+ {
13795
+ src: albumArtUrl,
13796
+ // We don't currently know these.
13797
+ // sizes: "96x96",
13798
+ // type: "image/png"
13799
+ },
13800
+ ]
13801
+ : [],
13802
+ });
13803
+ });
13804
+ // @ts-ignore TypeScript does not know about the Media Session API: https://github.com/Microsoft/TypeScript/issues/19473
13805
+ navigator.mediaSession.setActionHandler("play", () => {
13806
+ webamp.play();
13807
+ });
13808
+ // @ts-ignore TypeScript does not know about the Media Session API: https://github.com/Microsoft/TypeScript/issues/19473
13809
+ navigator.mediaSession.setActionHandler("pause", () => {
13810
+ webamp.pause();
13811
+ });
13812
+ // @ts-ignore TypeScript does not know about the Media Session API: https://github.com/Microsoft/TypeScript/issues/19473
13813
+ navigator.mediaSession.setActionHandler("seekbackward", () => {
13814
+ webamp.seekBackward(10);
13815
+ });
13816
+ // @ts-ignore TypeScript does not know about the Media Session API: https://github.com/Microsoft/TypeScript/issues/19473
13817
+ navigator.mediaSession.setActionHandler("seekforward", () => {
13818
+ webamp.seekForward(10);
13819
+ });
13820
+ // @ts-ignore TypeScript does not know about the Media Session API: https://github.com/Microsoft/TypeScript/issues/19473
13821
+ navigator.mediaSession.setActionHandler("previoustrack", () => {
13822
+ webamp.previousTrack();
13823
+ });
13824
+ // @ts-ignore TypeScript does not know about the Media Session API: https://github.com/Microsoft/TypeScript/issues/19473
13825
+ navigator.mediaSession.setActionHandler("nexttrack", () => {
13826
+ webamp.nextTrack();
13827
+ });
13828
+ }
13829
+ }
13830
+
13780
13831
  class Webamp {
13781
13832
  static VERSION = "1.5.0";
13782
13833
  _actionEmitter;
@@ -13804,6 +13855,9 @@
13804
13855
  this._actionEmitter = new Emitter();
13805
13856
  this.options = options;
13806
13857
  const { initialTracks, initialSkin, availableSkins, enableHotkeys = false, zIndex, requireJSZip, requireMusicMetadata, handleTrackDropEvent, handleAddUrlEvent, handleLoadListEvent, handleSaveListEvent, enableDoubleSizeMode, __butterchurnOptions, __customMediaClass, } = this.options;
13858
+ if (options.enableMediaSession) {
13859
+ enableMediaSession(this);
13860
+ }
13807
13861
  // TODO: Make this much cleaner
13808
13862
  let convertPreset = null;
13809
13863
  if (__butterchurnOptions != null) {
@@ -13926,12 +13980,24 @@
13926
13980
  isShuffleEnabled() {
13927
13981
  return getShuffle(this.store.getState());
13928
13982
  }
13983
+ /**
13984
+ * Toggle shuffle mode between enabled and disabled.
13985
+ */
13986
+ toggleShuffle() {
13987
+ this.store.dispatch(toggleShuffle());
13988
+ }
13929
13989
  /**
13930
13990
  * Check if repeat is enabled
13931
13991
  */
13932
13992
  isRepeatEnabled() {
13933
13993
  return getRepeat(this.store.getState());
13934
13994
  }
13995
+ /**
13996
+ * Toggle repeat mode between enabled and disabled.
13997
+ */
13998
+ toggleRepeat() {
13999
+ this.store.dispatch(toggleRepeat());
14000
+ }
13935
14001
  /**
13936
14002
  * Play the next track
13937
14003
  */