Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Setting Options for the Media Player

Why are my controls all messed up? I've got multiple play buttons on each element.

I'm using this code, and my player is completely messed up. It has two progress bars on the video, and two play buttons on the audio.

<div class="wrapper">
      <div class="videoWrapper">
    <h2>Video Example</h2>
    <video width="852" height="480" class="mejs__player">
      <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.mp4" type="video/mp4">
      <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge.ogg" type="video/ogg">
      <track label="English" kind="subtitles" srclang="en" src="bridge-captions.vtt" default>
    </video>
  </div>

  <div class="audioWrapper">
    <h2>Audio Example</h2>

    <audio class="mejs__player">
      <source src="http://treehouse-code-samples.s3.amazonaws.com/html-video-and-audio/bridge-audio.mp3" type="audio/mp3">
    </audio>
  </div>
</div>

<script>
  $('video, audio').mediaelementplayer({
    features: ['playpause', 'tracks', 'progress']
  });
</script>

1 Answer

I think it might have to do with you keeping the "mejs__player" classes while also passing the jQuery shorthand with the added script tag ( the one starting with $). Not sure, but this might end up causing the JS to link the mediaelementplayer elements twice to your page.