Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <audio src="https://assets.codepen.io/4358584/Anitek_-_Carry_On.mp3" controls loop></audio>
              
            
!

CSS

              
                audio {
  margin-top: 100px;
  margin-left: 100px;
}
              
            
!

JS

              
                const audio = document.querySelector('audio');

//array of mp3 srcs in the album order
const srcs = [
  'https://assets.codepen.io/4358584/Anitek_-_Komorebi.mp3',
  'https://assets.codepen.io/4358584/Anitek_-_Carry_On.mp3',
  'https://assets.codepen.io/4358584/Anitek_-_Wood_Note.mp3'
];

//array of song titles in the album order
const titles = [
  'Komorebi',
  'Carry On',
  'Wood Note'
]

if ( 'mediaSession' in navigator ) {
  navigator.mediaSession.metadata = new MediaMetadata({
    title: 'Carry On',
		artist: 'Anitek',
		album: 'MainStay',
		artwork: [
      { src: 'https://assets.codepen.io/4358584/1.300.jpg', sizes: '96x96', type: 'image/png' },
			{ src: 'https://assets.codepen.io/4358584/1.300.jpg', sizes: '128x128', type: 'image/png' },
			 { src: 'https://assets.codepen.io/4358584/1.300.jpg', sizes: '192x192', type: 'image/png' },
			 { src: 'https://assets.codepen.io/4358584/1.300.jpg', sizes: '256x256', type: 'image/png' },
			 { src: 'https://assets.codepen.io/4358584/1.300.jpg', sizes: '384x384', type: 'image/png' },
			 { src: 'https://assets.codepen.io/4358584/1.300.jpg', sizes: '512x512', type: 'image/png' }
    ]
  });

  navigator.mediaSession.setActionHandler('pause', () => {
    audio.pause();
  });
  navigator.mediaSession.setActionHandler('play', () => {
    audio.play();
  });
  navigator.mediaSession.setActionHandler('seekbackward', (details) => {
    audio.currentTime = audio.currentTime - (details.seekOffset || 10);
  });
  navigator.mediaSession.setActionHandler('seekforward', (details) => {
    audio.currentTime = audio.currentTime + (details.seekOffset || 10);
  });
  navigator.mediaSession.setActionHandler('previoustrack', () => {
    //find the index of the audio src in our srcs array to know what src to set next
    const index = srcs.indexOf(audio.src);
    
    //if the current track is not the first, set the src and corresponding title to that of the previous track of the current track
    if (index !== 0) {
      audio.src = srcs[index - 1];
      navigator.mediaSession.metadata.title = titles[index - 1];
    }
    
    //else set the src and title to the last in the arrays because the current track was the first in the album
    else {
      audio.src = srcs[2];
      navigator.mediaSession.metadata.title = titles[2];
    }
    
    //play the previous track
    audio.play();
  });
  navigator.mediaSession.setActionHandler('nexttrack', () => {
    //find the index of the audio src in our srcs array to know what src to set next
    const index = srcs.indexOf(audio.src);
    
    //if the current track is not the last, set the src and corresponding title to that of the next track of the current track
    if (index !== 2) {
      audio.src = srcs[index + 1];
      navigator.mediaSession.metadata.title = titles[index + 1];
    }
    
    //else set the src and title to the first in the arrays because the current track was the last in the album
    else {
      audio.src = srcs[0];
      navigator.mediaSession.metadata.title = titles[0];
    }
    
    //play the next track
    audio.play();
  });
}
              
            
!
999px

Console