native.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. Native.js
  3. This script is used to match the Music Player to as native as possible
  4. for some advanced use case (like PWA)
  5. */
  6. //Native Media Player
  7. function updateTitle(){
  8. if ('mediaSession' in navigator) {
  9. navigator.mediaSession.metadata = new MediaMetadata({
  10. title: 'Unforgettable',
  11. artist: 'Nat King Cole',
  12. album: 'The Ultimate Collection (Remastered)',
  13. artwork: [
  14. { src: 'https://dummyimage.com/96x96', sizes: '96x96', type: 'image/png' },
  15. { src: 'https://dummyimage.com/128x128', sizes: '128x128', type: 'image/png' },
  16. { src: 'https://dummyimage.com/192x192', sizes: '192x192', type: 'image/png' },
  17. { src: 'https://dummyimage.com/256x256', sizes: '256x256', type: 'image/png' },
  18. { src: 'https://dummyimage.com/384x384', sizes: '384x384', type: 'image/png' },
  19. { src: 'https://dummyimage.com/512x512', sizes: '512x512', type: 'image/png' },
  20. ]
  21. });
  22. navigator.mediaSession.setActionHandler('play', function() { /* Code excerpted. */ });
  23. navigator.mediaSession.setActionHandler('pause', function() { /* Code excerpted. */ });
  24. navigator.mediaSession.setActionHandler('stop', function() { /* Code excerpted. */ });
  25. navigator.mediaSession.setActionHandler('seekbackward', function() { /* Code excerpted. */ });
  26. navigator.mediaSession.setActionHandler('seekforward', function() { /* Code excerpted. */ });
  27. navigator.mediaSession.setActionHandler('seekto', function() { /* Code excerpted. */ });
  28. navigator.mediaSession.setActionHandler('previoustrack', function() { /* Code excerpted. */ });
  29. navigator.mediaSession.setActionHandler('nexttrack', function() { /* Code excerpted. */ });
  30. navigator.mediaSession.setActionHandler('skipad', function() { /* Code excerpted. */ });
  31. }
  32. }