title: Offering smaller versions of videos with media query or when mobiles are detected
body: <p>I went to this discussion from 2012: 
  <a href="https://stackoverflow.com/questions/10750874/how-to-load-different-video-for-mobile-devices-and-desktop-web-version">How to load different video for mobile devices and desktop web version?</a>
  because I was having the same problem. My mp4, webm and ogg videos of 7MB or so work fine on my desktop computer but hang up miserably on my Android smartphone.</p>
  
  <p>@Subhajit gave this sample code that he had tried unsuccessfully:</p>
  
  <pre><code>&lt;video controls&gt;
  &lt;source src="mySmallVideo.webm" type="video/webm" media="all and  (max-width:600px)"&gt;
  &lt;source src="myVideo.webm" type="video/webm"&gt;
  &lt;/video&gt;
  </code></pre>
  
  <p>and was referred to a stackoverflow discussion on the best way to detect a handheld device.</p>
  
  <p>But that only gave advice for detecting when the site was being viewed on a mobile device. Nobody offered alternative code to his sample, for showing a smaller version of the video after a mobile device was detected.</p>
  
  <p>My responsive site CSS code has <code>@media (max-width:</code> media queries. The one for mobile devices is set at 500px. How could I modify the sample code of @Subhajit to show a smaller version of a video, perhaps referencing the media query <code>@media (max-width: 500px)</code> coding in my CSS file?</p>
  
  <p>I'd rather not use mobile detection, commercial video players, or online storage sites.</p>
  
  <p>Thanks, @Fabio Here is my code so far from your first suggestion:</p>
  
  <pre><code>&lt;video controls&gt;
  &lt;source src="portfolioVideos/testMovieWEnd480x270.mp4.mp4" type="video/mp4" media="all and (max-width: 500px)"&gt;
  &lt;source src="portfolioVideos/testMovieWEnd480x270.webmsd.webm" type="video/webm" media="all and (max-width: 500px)"&gt;
  &lt;source src="portfolioVideos/testMovieWEnd720x405.mp4.mp4" type="video/mp4"&gt; 
  &lt;source src="portfolioVideos/testMovieWEnd720x405.webmsd.webm" type="video/webm"&gt;
  </code></pre>
  
  <p>I made two five-second "movies," consisting of a "test pattern" still which ends with a "the end" superimposed on it. The big movie for computer screens is 720x405 pixels and labeled "for 'puter." The small one for mobile screens is 480x270 pixels and is labeled "for mobile." When I alternate window sizes in Firefox and Safari (and refresh), they actually bring up the proper version. Chrome only shows the mobile version. (Reversing the order in the coded only makes everything worse.)</p>
  
  <p>The mobile version also comes up when I enter the video html in Mobile Phone Emulator. But when I call it up on my Android smartphone, the vid is so minascule I can't read which version it is, or even click on it.</p>
  
  <p>I looked at that the Chris Coyier page you recommended, but I couldn't figure it out. How would I search for more on this jQuery code? Thanks for previous and any possible follow.</p>
  
  <p>I tried taking a couple of new tacks on this problem. </p>
  
  <p>First, I tried using a jquery "window width" method and an if/else conditional to bring either a small or large version of the video into an iframe.</p>
  
  <pre><code>$(document).ready(function () {
  if ($(window).width() &lt; 550) {
  &lt;iframe src=... width="480" height="270"&gt;&lt;/iframe&gt;
  }
  else {
  &lt;iframe src=... width="720" height="405"&gt;&lt;/iframe&gt;
  }
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>That didn't work. Safari and Chrome both give me an "Unexpected token '&lt;'" error, which I understand "happens when you're including or posting to a file which doesn't exist." These files exist and work when opened directly. I tried using absolute urls, as recommended by @amenadiel, but that didn't work either.</p>
  
  <p>Second, I tried "window location" with an if/else conditional.</p>
  
  <pre><code>$(document).ready(function () {
  if ($(window).width() &lt; 330) {
  window.location.href = ...;
  }
  else {
  window.location.href = ...;
  }
  });
  </code></pre>
  
  <p>This works when tested in the various simulated devices and window sizes on two online emulators. But it doesn't work on my Android smartphone. There, just a tiny, empty, unclickable video window in the upper left of the screen.</p>
  
  <p>I may have answered my own question.</p>
  
  <p>I found here:
  <a href="https://github.com/etianen/html5media/wiki/embedding-video" rel="noreferrer">https://github.com/etianen/html5media/wiki/embedding-video</a></p>
  
  <p>this super simple code:</p>
  
  <pre><code>&lt;meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;video poster="poster.jpg" width="618" height="347" controls preload&gt; 
  &lt;source src="video.mp4" media="only screen and (min-device-width: 568px)"&gt;&lt;/source&gt; 
  &lt;source src="video.iphone.mp4" media="only screen and (max-device-width: 568px)"&gt;&lt;/source&gt; 
  &lt;/video&gt;
  </code></pre>
  
  <p>which seems, miraculously, to have worked. Check out this page, 
  <a href="http://willsoper.net/videoPortfolio.html" rel="noreferrer">http://willsoper.net/videoPortfolio.html</a>
  which contains two videos, each with a large and small version.
  Try the "Test Pattern" one on the right first; it's only ten seconds long. The larger version is labeled "for 'puter" and the smaller one, "for Mobi." On my Samsung Galaxy Android in vertical position, the "Mobi" version appears. If I hit the back button, turn the phone to horizontal, and try it again, the larger, "'puter" version appears.</p>
  
  <p>The video on the left, with the man, also has a small and large version and seems to work the same way. It is much longer and on my smartphone it sometimes re-buffers briefly once or twice.</p>
  
  <p>Ironically, my previous coding worked in online emulators but not on my actual smartphone. This one works on my smartphone but not on the emulators.</p>
  
  <p>I'd appreciate knowing what others, especially @Fabio , experience and how I might improve on the code.</p>