<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>MediaStuff</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/mediastuff/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/mediastuff/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 04:04:30 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Last post as a 'softie'</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/last-post-as-a-softie</link>
      <pubDate>Sun, 21 Sep 2014 18:01:00 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/09/21/last-post-as-a-softie/</guid>
      <description><![CDATA[Microsoft and I have parted ways as of November 17. Thanks for your support and keep watching...]]></description>
      <content:encoded><![CDATA[<p>Microsoft and I have parted ways as of November 17. Thanks for your support and keep watching Internet Explorer, If you'd like to see what kinds of things IE is working on, check out the<a href="https://status.modern.ie/"> modern.ie status site</a>.</p>
<p>The modern.ie site also has a really cool way to test with&nbsp;various versions of IE,&nbsp;by using VM technology. In addition to&nbsp;versions of Internet Explorer from 6 through 11, you can get VM&nbsp;images for Mac or Linux based virtual machines. Check&nbsp;out <a href="https://modern.ie/en-us/virtualization-tools#downloads">virtualization tools</a>, also&nbsp;on&nbsp;modern.ie.&nbsp;</p>
<p>So with that, I'll say 'see ya'</p>
<p>-Jay</p>]]></content:encoded>
    </item>
    <item>
      <title>Show me!  Explain it with an example</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/show-me-explain-it-with-an-example</link>
      <pubDate>Mon, 05 May 2014 19:47:00 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/05/05/show-me-explain-it-with-an-example/</guid>
      <description><![CDATA[When I first started documenting canvas APIs (way back in IE9), I needed to create examples for...]]></description>
      <content:encoded><![CDATA[<p>When I first started documenting canvas APIs (way back in IE9), I needed to create examples for myself&nbsp;to understand how they worked. This is a&nbsp;pretty common practice when documenting code. In most cases,&nbsp;the examples made it into the topics to illustrate how to use the API.</p>
<p>Recently, I've&nbsp;gone back and put those examples onto our sample server to eliminate the need to copy and paste code to see the API in action. I came across three samples that took a step just a little farther than just figuring out how the API was called. These examples actually showed some key issues, and really helped my own understanding. Additionally, the output from two of them were used as screen shots&nbsp;to illustrate the concepts.</p>
<h3>lineCap property</h3>
<p>The first example was the <a href="https://msdn.microsoft.com/en-us/library/ie/ff974910(v=vs.85).aspx" target="_blank">lineCap</a> property which specifies how to terminate a line. You can assign one of three string values; butt, round, and square. The butt value tells canvas to not put any cap on the end of a line. The round value tells it to put on a round end, and square&nbsp;makes&nbsp;a square end. Round and square&nbsp;both&nbsp;extend the line&nbsp;approximately 1/2&nbsp;the line width,&nbsp;for each cap.</p>
<p>That little bit of extra space could cause some problems, as the caps add to the specified line length. This&nbsp;is an issue if you're trying to accurately place your lines. I explained that concept with words&nbsp;in the topic, but realized a picture&nbsp;tells a better story.&nbsp;To do that,&nbsp;I created an <a href="https://samples.msdn.microsoft.com/Workshop/samples/canvas/linecap.html" target="_blank">example</a>&nbsp;showing the concept. I added some vertical lines to show what the exact lengths of the lines, and how much the caps add.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/4705.linecapillustration_06C391CF.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/4705.linecapillustration_5F00_06C391CF.jpg"><img style="display: inline; background-image: none;" title="linecapillustration" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/8037.linecapillustration_thumb_0D769B52.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/8037.linecapillustration_5F00_thumb_5F00_0D769B52.jpg" alt="linecapillustration" width="207" height="244" border="0" /></a></p>
<h3>arcTo method</h3>
<p>The next example is the <a href="https://msdn.microsoft.com/en-us/library/ie/ff975306(v=vs.85).aspx" target="_blank">arcTo method</a>.</p>
<p>The arcTo&nbsp;method draws an arc between two imaginary tangents,&nbsp;as the&nbsp;<a href="https://rawgit.com/w3c/html/html5_canvas_CR/TR/Overview.html">W3C</a>&nbsp;spec&nbsp;describes it. This description required me to dig back into what I should have remembered from my high school geometry class (I didn't really pay attention). <br /> <br /> For <a href="https://samples.msdn.microsoft.com/Workshop/samples/canvas/arcto.htm" target="_blank">the example</a> I drew two arcs. One made a nice rounded corner between two straight lines. The other didn&rsquo;t complete the rounded corner because the tangents were closer together. I drew both the straight lines (in black), and the imaginary lines (in blue) to show the relationship. Maybe for you it would be obvious, but at the time it helped me understand how all the parameters worked together.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/7532.arcTo1_6D5B8E94.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/7532.arcTo1_5F00_6D5B8E94.png"><img style="display: inline; background-image: none;" title="arcTo1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/8831.arcTo1_thumb_4216F78D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/8831.arcTo1_5F00_thumb_5F00_4216F78D.png" alt="arcTo1" width="232" height="218" border="0" /></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/2063.arcTo2_740E9817.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/2063.arcTo2_5F00_740E9817.png"><img style="display: inline; background-image: none;" title="arcTo2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/7853.arcTo2_thumb_68E50DCD.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/7853.arcTo2_5F00_thumb_5F00_68E50DCD.png" alt="arcTo2" width="232" height="218" border="0" /></a> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<h3>miterLimit property</h3>
<p>Lastly, the <a href="https://msdn.microsoft.com/en-us/library/ie/ff975306(v=vs.85).aspx" target="_blank">miterLimit property</a>. This&nbsp;property is a ratio of the angle when two lines come together. The ratio&nbsp;describes&nbsp;whether the desired effect of the <a href="https://msdn.microsoft.com/en-us/library/ie/ff974911(v=vs.85).aspx" target="_blank">lineJoin</a> miter happens property. LineJoin specifies how&nbsp;canvas&nbsp;draws the intersection when two lines come together (say on a triangle). LineJoin&rsquo;s options are bevel, round, and miter. When using a bevel or round lineJoin,&nbsp;the miterLimit&nbsp;setting has no effect. <br /> <br /> However when you set lineJoin to miter (which brings the two lines to a point), miterLimit&nbsp;controls whether canvas draws a point or a squared edge corner. If the calculated ratio ((lineWidth / 2 ) / miter length) is below the miterLimit, you get a squared off edge.&nbsp;</p>
<p>Experimenting with different hardcoded lineWidths and miterLimits didn't show the difference very well. Taking one of the examples, I substituted HTML5 slider controls so I could independently control the line width, angle of the two lines, and the miterLimit. If you're using IE9 then you'll&nbsp;see text&nbsp;boxes instead of sliders. Sorry, it's worth the upgrade to a later version of IE.<br /> <br />Viola! I was able to get the point to disappear and reappear, based on the values I slid into place. <br /> <br />Here&rsquo;s the <a href="https://samples.msdn.microsoft.com/Workshop/samples/canvas/miterlimit.html" target="_blank">final example</a>:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/5710.miterlimitexample_2FCE30CB.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/5710.miterlimitexample_5F00_2FCE30CB.png"><img style="display: inline; background-image: none;" title="miterlimitexample" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/1581.miterlimitexample_thumb_61C5D155.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/1581.miterlimitexample_5F00_thumb_5F00_61C5D155.png" alt="miterlimitexample" width="404" height="328" border="0" /></a></p>
<h3>See the code</h3>
<p>There are&nbsp;lots of samples that show how to use an API in the <a href="https://msdn.microsoft.com/en-us/library/ie/hh771733(v=vs.85).aspx">reference content</a>. However these are among my favorites as they show how to write the syntax, and illustrate some of the concepts of the API.</p>
<p>For the code behind these examples, check out:</p>
<p><a href="https://msdn.microsoft.com/en-us/library/ie/ff974910(v=vs.85).aspx" target="_blank">lineCap property</a></p>
<p><a href="https://msdn.microsoft.com/en-us/library/ie/ff975306(v=vs.85).aspx" target="_blank">arcTo method</a></p>
<p><a href="https://msdn.microsoft.com/en-us/library/ie/ff974913(v=vs.85).aspx" target="_blank">miterLimit property</a></p>
<p>Let me know what you think!</p>]]></content:encoded>
    </item>
    <item>
      <title>Saved by the bell…uh test – addTextTrack not at risk!</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/saved-by-the-belluh-test-addtexttrack-not-at-risk</link>
      <pubDate>Wed, 16 Apr 2014 14:48:00 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/04/16/saved-by-the-belluh-test-addtexttrack-not-at-risk/</guid>
      <description><![CDATA[While I was at the W3C Face to Face conference, I saw that the addTextTrack method was on the...]]></description>
      <content:encoded><![CDATA[<p>While I was at the W3C Face to Face conference, I saw that the <a href="https://msdn.microsoft.com/en-us/library/ie/dn254953(v=vs.85).aspx" target="_blank">addTextTrack</a> method was on the at-risk list for HTML5. As I had written an example and a reference page to document that API, I asked Robin Berjon about it. We brought it up on the screen and it appeared to be supported by at least a couple of browsers. It seemed the test was faulty. We tagged it as discussed at the F2F.</p>
<p>A few days later, Sylvia, one of the editors for the media spec brought it up again. I posted a copy of my <a href="https://samples.msdn.microsoft.com/Workshop/samples/media/addtexttracktest.html" target="_blank">example</a> (and got smacked down for not including more formats) to show it worked in at least Chrome and IE. My example only had an MP4 format video, as I was linking to one on the IE Testdrive site. Anyway, long story short, Phillip reported back that test was fixed, and indeed both IE and Chrome passed the test.</p>
<h3>What's the addTextTrack do?</h3>
<p>Normally to get closed captioning, a video publisher would create a separate WebVTT or TTML format file (see <a href="https://blogs.msdn.com/b/mediastuff/archive/2014/03/05/closed-captioning-it-s-not-just-for-accessibility-texttrack-in-html5-video.aspx" target="_blank">Closed captioning, it&rsquo;s not just for accessibility! TextTrack in HTML5</a> video for more on these formats). You can create different files for different languages, or purposes, such as scripting external content, etc.</p>
<p>But the problem is that you have to prepare the text track file ahead of time. Enter <a href="https://msdn.microsoft.com/en-us/library/ie/dn254953(v=vs.85).aspx" target="_blank">addTextTrack</a>! As specified in the <a href="https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-addtexttrack" target="_blank">W3C</a>, it&nbsp;lets you create <a href="https://msdn.microsoft.com/en-us/library/ie/hh772673(v=vs.85).aspx">textTracks</a> as the content is playing. You can create the content programmatically based on input or other factors, or you could download updated content from your website using XML Header Request (XHR). You could even use addTextTrack as a work around for servers that don't know what to do with a WebVTT or TTML MIME type. One man's text is another man's captions, so to speak.</p>
<p>For&nbsp;an <a href="https://msdn.microsoft.com/en-us/library/ie/dn254953(v=vs.85).aspx" target="_blank">addTextTrack</a>&nbsp;example, I create a simple&nbsp;caption track&nbsp;displaying the numbers&nbsp;0 to 30&nbsp;displayed every&nbsp;5 seconds. It's very contrite, but&nbsp;shows the concept. See the <a href="https://samples.msdn.microsoft.com/Workshop/samples/media/addtexttracktest.html" target="_blank">example live online</a>. Note that the online example only has&nbsp;an MP4 file link.</p>
<p>This source code has an MP4 and an OGG format video file. The source is a link to <a href="https://archive.org/details/movies" target="_blank">Archive.org</a> and an old BBC technology series called <a href="https://archive.org/details/bad-influence" target="_blank">Bad Influence.</a>&nbsp;</p>
<h5>Legal note: Most of the content on the archive.org site is either creative commons license, or public domain. All rights of these clips remain with either archive.org or the BBC, and are here only for demonstration purposes.</h5>
<p><a href="https://samples.msdn.microsoft.com/Workshop/samples/media/addtexttracktest.html" target="_blank">This example</a> works in Internet Explorer 11 and the latest version of Chrome. The video plays but the tracks don't show on Firefox. While addTextTrack is&nbsp;in the spec, the TextTrackCue constructor isn't. The <a href="https://msdn.microsoft.com/en-us/library/ie/dn254953(v=vs.85).aspx" target="_blank">addTextTrack</a> constructor has been dropped in favor of the VTTCue&nbsp;constructor. I'm now looking for addTextTrack code that will work on other browsers. Suggestions?</p>
<p>&nbsp;</p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html &gt;</span></p>
<p><span style="font-family: Courier New;">&lt;html &gt; <br />&nbsp; &lt; head&gt; <br />&nbsp;&nbsp;&nbsp; &lt;title&gt;Add Text Tracks example&lt;/title&gt; <br />&lt; /head&gt; <br />&lt; body&gt;</span></p>
<p><span style="font-family: Courier New;">&lt;video id="video1" controls="controls" muted="muted"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- change to your own mp4 video file -&ndash;&gt;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- show using multiple file formats --&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp; &lt;source src="</span><a href="https://archive.org/download/bad_influence_se4ep13/Bad.Influence.se4ep13.mp4&quot;"><span style="font-family: Courier New;">https://archive.org/download/bad_influence_se4ep13/Bad.Influence.se4ep13.mp4"</span></a><span style="font-family: Courier New;"> /&gt;&nbsp; <br />&nbsp; &lt;source src="</span><a href="https://archive.org/download/bad_influence_se4ep13/Bad.Influence.se4ep13.ogv&quot;"><span style="font-family: Courier New;">https://archive.org/download/bad_influence_se4ep13/Bad.Influence.se4ep13.ogv"</span></a><span style="font-family: Courier New;"> /&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp; HTML5 Video not supported <br />&lt; /video&gt;</span></p>
<p><span style="font-family: Courier New;"> &lt;script&gt; <br />&nbsp;&nbsp;&nbsp; var video = document.getElementById("video1"); <br />&nbsp;&nbsp;&nbsp; var startTime, endTime, message; <br />&nbsp;&nbsp;&nbsp; var newTextTrack = video.addTextTrack("captions", "sample"); <br />&nbsp;&nbsp;&nbsp; newTextTrack.mode = newTextTrack.SHOWING; // set track to display <br />&nbsp;&nbsp;&nbsp; // create some cues and add them to the new track <br />&nbsp;&nbsp;&nbsp; for(var i=0;i&lt;30;i++){ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startTime =&nbsp; i * 5 ; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endTime = ( (i * 5) +&nbsp; 5); </span><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message =&nbsp; "This is number " + i; </span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // this constructor deprecated according to the new spec&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newTextTrack.addCue(new TextTrackCue(startTime, endTime, message)); <br />&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp; video.play(); <br />&nbsp; &lt;/script&gt; <br />&lt; /body&gt; <br />&lt; /html&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /></span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Taking a little time at the W3C Face to Face</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/taking-a-little-time-at-the-w3c-face-to-face</link>
      <pubDate>Fri, 11 Apr 2014 19:53:00 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/04/11/taking-a-little-time-at-the-w3c-face-to-face/</guid>
      <description><![CDATA[I took a few days away from slaving over a hot keyboard to travel a little. I attended the W3C Face...]]></description>
      <content:encoded><![CDATA[<p>I took a few days away from slaving over a hot keyboard to travel a little. I attended the W3C Face to Face (F2F) in San Jose the first half of the week. As one of the editors of the W3C Canvas 2D Context spec the F2Fs are something that we periodically get called out to do. This was my first, though I've been an editor since Oct 2012. While the F2F was really interesting, and I learned a lot about how the W3C does business, and also about technologies outside my realm. Unfortunately, pretty much all the other canvas editors had other things to go to, so we didn't have a session on the spec.</p>
<p>The 2D Context spec is in the final stages of going to <a href="https://www.w3.org/html/wg/drafts/2dcontext/html5_canvas_CR/" target="_blank">Candidate Recommendation</a> (CR), and has accessibility issues that are still being worked on. The canvas editors and the accessibility editors are getting together in a task force to talk about hit testing and focus rings. drawSystemFocusRing, which has been renamed&nbsp; drawFocusAsNeeded. Focus rings is pretty much set.</p>
<p>Hit regions are still under discussion. They're a cool feature that if implemented, lets a developer define controls made of paths on the canvas, and associates them with controls (like buttons) that live in the fallback area between the &lt;canvas&gt; and &lt;/canvas&gt; tags.</p>
<p>&nbsp; Currently if a browser supports canvas, then what's between the tags is ignored, mostly. For example this snippet:&nbsp;</p>
<p><span style="font-family: Courier New;">&lt;canvas id="mycanvas"&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp; Sorry, this browser or mode does not support canvas.</span></p>
<p><span style="font-family: Courier New;">&lt;/canvas&gt;</span></p>
<p>Obviously, if the browser doesn't support canvas, the fallback code (or text in this case), is displayed. You can also put interactive elements, like buttons in that space, like this:</p>
<p><span style="font-family: Courier New;">&lt;canvas id="mycanvas"&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp; &lt;button id="mybutton"&gt;Click me&lt;/button&gt;</span></p>
<p><span style="font-family: Courier New;">&lt;/canvas&gt;</span></p>
<p>Visually, if your browser supports canvas you're not going to see the button. If canvas isn't supported, then the button will show. However, there's a third option that only people who use assistive technology might know about. If your browser supports canvas, and it has say a screen reader hooked up, the button is "visible" to the reader.</p>
<p>Hit regions lets you put your button inside the canvas tags, create a button on the canvas (say using fillrect()), and link the two together as a hit region. The idea is that when the control gets focus, it can optionally alert the accessibility equipment. Additionally there's some updates (still discussing it) to mouse events so when you click on an area of the canvas that has a hit region, it sends a mouse message to the associated control that's between the canvas tags.</p>
<p>Now this will go a long way to making canvas accessible. But, if we can get the mouse events in, that's a win for everyone. You'll be able to easily create an interface by using elements in the fallback area, put some splashy graphics on the canvas, and have it work just like a regular UI. That would be cool.</p>
<p>We're still talking about hit regions, but hopefully we'll get the last things nailed down this week and move the spec back to CR. More later.</p>]]></content:encoded>
    </item>
    <item>
      <title>TURN THAT DOWN! Pausing or changing the volume of media when you leave the page</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/turn-that-down-pausing-or-changing-the-volume-of-media-when-you-leave-the-page</link>
      <pubDate>Fri, 28 Mar 2014 15:33:00 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/03/28/turn-that-down-pausing-or-changing-the-volume-of-media-when-you-leave-the-page/</guid>
      <description><![CDATA[Looking through customer comments on my topic, Getting Started with the HTML5 Audio Element, I found...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: small;">Looking through customer comments on my topic, <a href="https://msdn.microsoft.com/library/ie/gg589529" target="_blank">Getting Started with the HTML5 Audio Element</a>, I found a question that was similar to another comment; how to&nbsp;lower the&nbsp;volume or&nbsp;stop a video when you go to another page&nbsp;on a website. </span></p>
<p><span style="font-size: small;">I hadn't tried that before, so I experimented with the <a href="https://msdn.microsoft.com/en-us/library/ie/ms536934(v=vs.85).aspx" target="_blank">focus</a> and <a href="https://msdn.microsoft.com/en-us/library/ie/ms536909(v=vs.85).aspx" target="_blank">blur</a> events. It turned out to be relatively easy, as long as I watched for events that called other events. </span></p>
<h3>Using the focus and blur events</h3>
<p><span style="font-size: small;">The focus and blur events aren't directly related to the media (<a href="https://msdn.microsoft.com/en-us/library/ie/hh772923(v=vs.85).aspx" target="_blank">audio</a> or <a href="https://msdn.microsoft.com/en-us/library/ie/hh772959(v=vs.85).aspx" target="_blank">video</a>) object, they're actually on the <a href="https://msdn.microsoft.com/en-us/library/ie/ms535873(v=vs.85).aspx" target="_blank">window</a> object. The focus event fires when a webpage gets focus (that is, ready to interact with you). The blur event fires when you lose focus. Using them is pretty straight forward: </span></p>
<p><span style="font-family: courier new; font-size: x-small;">// when you leave a page</span></p>
<p><span style="font-family: courier new; font-size: x-small;">window.addEventListener("blur", function(){ <br />&nbsp;&nbsp; //do something here <br />}, false); </span></p>
<p><span style="font-family: courier new; font-size: x-small;">// when you return (or open) to a page</span></p>
<p><span style="font-family: courier new; font-size: x-small;">window.addEventListener("focus",function(){ <br />&nbsp; // do something else here <br />}</span></p>
<p><span style="font-size: small;">Now you need to add code to the "do something part. </span></p>
<p><span style="font-size: small;"><span style="font-size: small;">To test the examples here open two tabs, one with the sample, and another page (anything will do). </span></span></p>
<h3>Pause video on leaving, pickup when you come back</h3>
<p><span style="font-size: small;">For simplicity, I'm using an <a href="https://msdn.microsoft.com/en-us/library/ie/hh772923(v=vs.85).aspx" target="_blank">audio</a> element, but you can do this as well with <a href="https://msdn.microsoft.com/en-us/library/ie/hh772959(v=vs.85).aspx" target="_blank">video</a>. This example plays a clip of audio and pauses when you go to another tab or even switch to another app. The "wasPlaying" flag tracks whether the audio was playing or not when you lost focus. </span></p>
<p><span style="font-size: small;">The one issue I had is how to keep the "wasPlaying" flag current. The best way is to use the "<a href="https://msdn.microsoft.com/en-us/library/ie/ff974163(v=vs.85).aspx" target="_blank">play</a>" or "<a href="https://msdn.microsoft.com/en-us/library/ie/ff974160(v=vs.85).aspx" target="_blank">pause</a>" events to set the flag. We've used this technique in <a href="https://blogs.msdn.com/b/mediastuff/archive/2014/03/21/flicks-for-the-filling-creating-a-video-fill-pattern-in-canvas.aspx" target="_blank">previous media posts</a> where we&nbsp;change the Play button text. In the "<a href="https://msdn.microsoft.com/en-us/library/ie/ff974163(v=vs.85).aspx" target="_blank">play</a>" event handler, we set "wasPlaying" to true. In the "<a href="https://msdn.microsoft.com/en-us/library/ie/ff974160(v=vs.85).aspx" target="_blank">pause</a>" event handler, we set it to false. </span></p>
<p><span style="font-size: small;">In addition to setting the "wasPlaying" flag, we need an additional flag to tell us that we are leaving when we call pause.&nbsp;I did this because </span><span style="font-size: small;">when you call pause, it fires the pause event, which&nbsp;in turn sets&nbsp; the "wasPlaying" flag to false. If we didn't track that we were leaving, we'd pause the audio when we lost focus. However, when we return, the "wasPlaying" flag&nbsp;is set to false in the "<a href="https://msdn.microsoft.com/en-us/library/ie/ff974160(v=vs.85).aspx" target="_blank">pause</a>" event, and we wouldn't call play() to get started again. </span></p>
<p><span style="font-size: small;">Confused? Try commenting out the "leaving" flag and you'll see what happens. </span><span style="font-size: small;">We also always initialize the leaving flag, because an uninitialized flag can be unpredictable.&nbsp; <a href="https://samples.msdn.microsoft.com/Workshop/samples/media/audio/audiolosefocus.html" target="_blank">Try this example</a> online. </span></p>
<p><span style="font-family: courier new;">&lt;!doctype html&gt;&nbsp; <br />&lt; html&gt; <br />&lt; head&gt; <br />&nbsp;&nbsp;&nbsp; &lt;title&gt;Audio Element Sample&lt;/title&gt; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp;&nbsp;&nbsp; &lt;h1&gt;Audio Element Sample&lt;/h1&gt; <br />&nbsp;&nbsp;&nbsp; &lt;!-- Display the audio player with control buttons. --&gt; <br />&nbsp;&nbsp;&nbsp; &lt;audio id="myaudio" src="</span><a href="https://testdriveie9.wise.glbdns.microsoft.com/ietestdrivecontent/Musopen.Com"><span style="font-family: courier new;">https://testdriveie9.wise.glbdns.microsoft.com/ietestdrivecontent/Musopen.Com</span></a><span style="font-family: courier new;"> Symphony No. 5 in C Minor, Op. 67 - I. Allegro con brio.mp3" controls autoplay loop&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HTML5 audio not supported <br />&nbsp;&nbsp;&nbsp; &lt;/audio&gt; <br />&nbsp;&nbsp;&nbsp; &lt;script&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var audio =document.getElementById("myaudio");</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var wasPlaying; // set this to true sometime if playing <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var leaving = false;</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.addEventListener("blur", function () {</span><span style="font-family: courier new;"> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leaving = true; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (wasPlaying) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.pause(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.addEventListener("focus", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (wasPlaying == true) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.play(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leaving = false; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.addEventListener("play", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wasPlaying = true; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.addEventListener("pause", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!leaving) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wasPlaying = false; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &lt;/script&gt; <br />&lt; /body&gt; <br />&lt; /html&gt;</span></p>
<h3>Cut the volume when you leave</h3>
<p><span style="font-size: small;">Sometimes you don't want to stop the music when you leave a page, just turn it down a little. This example is actually simpler than pausing the music, because we don't need to worry about setting a special flag when we fire pause/play events. </span></p>
<p><span style="font-size: small;">To adjust the volume, we&nbsp;set the <a href="https://msdn.microsoft.com/en-us/library/ie/ff974764(v=vs.85).aspx" target="_blank">volume property</a> on the media object. Volume is set between 0 and 1. When we lose focus, we're setting the volume to 1/3 what it was. You can set it to anything (even full volume to get users back to your page if you want). We stash the current volume in a global variable when we lose focus so we can reset it when we come back. </span></p>
<p><span style="font-size: small;"><a href="https://samples.msdn.microsoft.com/Workshop/samples/media/audio/audioloseFocusVolume.html" target="_blank">Try this example</a> online. </span></p>
<p><span style="font-family: courier new;">&lt;!doctype html&gt;&nbsp; <br />&lt; html&gt; <br />&lt; head&gt; <br />&nbsp;&nbsp;&nbsp; &lt;title&gt;Audio Element Sample&lt;/title&gt; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp;&nbsp;&nbsp; &lt;h1&gt;Audio Element Sample&lt;/h1&gt; <br />&nbsp;&nbsp;&nbsp; &lt;!-- Display the audio player with control buttons. --&gt; <br />&nbsp;&nbsp;&nbsp; &lt;audio id="myaudio" src="</span><a href="https://testdriveie9.wise.glbdns.microsoft.com/ietestdrivecontent/Musopen.Com"><span style="font-family: courier new;">https://testdriveie9.wise.glbdns.microsoft.com/ietestdrivecontent/Musopen.Com</span></a><span style="font-family: courier new;"> Symphony No. 5 in C Minor, Op. 67 - I. Allegro con brio.mp3" controls autoplay loop&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HTML5 audio not supported <br />&nbsp;&nbsp;&nbsp; &lt;/audio&gt; <br />&nbsp;&nbsp;&nbsp; &lt;script&gt;</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var wasPlaying = false; // set this to true sometime if playing <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var wasVolume;&nbsp;&nbsp; // save the current volume when we lose focus <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var audio = document.getElementById("myaudio");</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.addEventListener("blur", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (wasPlaying) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wasVolume = audio.volume;&nbsp;&nbsp; // save the current volume <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.volume = wasVolume / 3; // or any volume setting <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.addEventListener("focus", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // if we were playing when we lost focus, reset volume when we come back <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (wasPlaying == true) {&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.volume = wasVolume; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.addEventListener("play", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wasPlaying = true; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; audio.addEventListener("pause", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wasPlaying = false; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: courier new;">&nbsp;&nbsp;&nbsp; &lt;/script&gt; <br />&lt; /body&gt; <br />&lt; /html&gt;</span></p>]]></content:encoded>
    </item>
    <item>
      <title>Play it again… creating an audio playlist page, and refreshing old content</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/play-it-again-creating-an-audio-playlist-page-and-refreshing-old-content</link>
      <pubDate>Thu, 27 Mar 2014 11:00:00 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/03/27/play-it-again-creating-an-audio-playlist-page-and-refreshing-old-content/</guid>
      <description><![CDATA[I really like to get feedback on the topics I write, good or bad. The good ones immediately get...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: small;">I really like to get <a href="https://blogs.msdn.com/b/mediastuff/archive/2014/02/17/feed-me-feed-me-giving-good-feedback-on-topics.aspx" target="_blank">feedback on the topics</a> I write, good or bad. The good ones immediately get forwarded to my boss in hopes of a few more points in my review. The bad ones I try to fix the topics to make them better.</span></p>
<p><span style="font-size: small;">Some recent feedback wasn't bad, but rather a suggestion. "Luke" posted a comment on my topic "Using JavaScript to Control the Audio Object". He said that he'd like to change songs on the fly with a pick list. The original example had a text box that you could write in your own audio file to play, so it really didn't fit the bill.</span></p>
<p><span style="font-size: small;">On the Internet Explorer Testdrive site, there's a <a href="https://ie.microsoft.com/testdrive/HTML5/HTML5AudioXMLPlaylist/Default.html" target="_blank">slick multi-file player</a> that uses SVG, audio, and XML. For something a little simpler (seems to be a theme song in here somewhere), the mods I did to my original single song player might do the trick. </span></p>
<h3>Specifying a source file on an audio element</h3>
<p><span style="font-size: small;">There are two ways to assign a URL to an audio element in HTML, use the <a href="https://msdn.microsoft.com/en-us/library/ie/ff974762(v=vs.85).aspx" target="_blank">src</a> attribute on the audio element or use the <a href="https://msdn.microsoft.com/en-us/library/ie/ff975070(v=vs.85).aspx" target="_blank">source</a> element between the <a href="https://msdn.microsoft.com/en-us/library/ie/hh772923(v=vs.85).aspx" target="_blank">audio</a> tags. The src attribute is good when you have just a single file that you're going to play.</span></p>
<p><span style="font-size: small;">Here's an ultra simple audio player:</span></p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt; <br />&lt; html&gt; <br />&nbsp; &lt;head&gt; <br />&nbsp;&nbsp;&nbsp; &lt;title&gt;Simple Audio Example&lt;/title&gt; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp; &lt;audio control src="songfile.mp3" &gt;Not supported&lt;/audio&gt; <br />&lt; /body&gt; <br />&lt; /html&gt;</span></p>
<p><span style="font-size: small;">If you want to give the audio element a few choices of format, such as mp3, aac, or ogg, then you'll want to use the </span><a href="https://msdn.microsoft.com/en-us/library/ie/ff975070(v=vs.85).aspx" target="_blank"><span style="font-size: small;">source</span></a><span style="font-size: small;"> elements. </span></p>
<p><span style="font-family: Courier New;">&lt;!doctype html&gt; <br />&lt; head&gt; <br />&nbsp;&nbsp;&nbsp; &lt;title&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Multiple format audio example <br />&nbsp;&nbsp;&nbsp; &lt;/title&gt; <br />&nbsp;&nbsp;&nbsp; &lt;!-- Uncomment the following meta tag if you have issues rendering this page on an intranet site. --&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;!--&nbsp; &lt;meta http-equiv="X-UA-Compatible" content="IE=9"/&gt; --&gt; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp;&nbsp;&nbsp; &lt;h1&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using source to support multiple audio formats <br />&nbsp;&nbsp;&nbsp; &lt;/h1&gt; <br />&nbsp;&nbsp;&nbsp; &lt;!-- The browser will automatically choose the format it supports. --&gt; <br />&nbsp;&nbsp;&nbsp; &lt;audio controls="true"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source src="demo.mp3" type="audio/mp3"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source src="demo.ogg" type="audio/ogg"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source src="demo.aac" type="audio/mp4"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- If no support at all. --&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HTML5 audio not supported <br />&nbsp;&nbsp;&nbsp; &lt;/audio&gt; <br />&lt; /body&gt; <br />&lt; /html&gt;</span></p>
<p><span style="font-size: small;">The </span><a href="https://msdn.microsoft.com/en-us/library/ie/ff975070(v=vs.85).aspx" target="_blank"><span style="font-size: small;">source</span></a><span style="font-size: small;"> element takes a single src attribute, but you can stack up as many elements as you have formats for a given file. The &lt;audio&gt; element&nbsp;picks the first format it can play. If you try to put three different mp3 songs in &lt;source&gt; elements, only the first will play, every time. Unlike the </span><a href="https://msdn.microsoft.com/en-us/library/ie/hh772556(v=vs.85).aspx" target="_blank"><span style="font-size: small;">track</span></a><span style="font-size: small;"> element which similarly resides between the </span><a href="https://msdn.microsoft.com/en-us/library/ie/hh772959(v=vs.85).aspx" target="_blank"><span style="font-size: small;">video</span></a><span style="font-size: small;"> element tags, you have no control, selection is automatic. </span></p>
<h3>Swapping different audio source files</h3>
<p><span style="font-size: small;">To set up multiple sources, like a playlist, you need to write a little JavaScript. When you want to change songs on an audio control, you can simply assign a new URL to the src property and call play(). There is one gotcha that can pop up. If you originally specified a song with the source element, you need to add one step, call load() before calling play().</span></p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt;</span></p>
<p><span style="font-family: Courier New;">&lt;html&gt; <br />&lt; head&gt; <br />&nbsp;&nbsp;&nbsp; &lt;title&gt;Simple song switcher&lt;/title&gt; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp; &lt;audio controls="controls" id="myaudio"&gt; <br />&nbsp;&nbsp;&nbsp; source src="firstaudiofile.mp3" type="audio/mp3"&gt; <br />&nbsp;&nbsp;&nbsp; Sorry, HTML5 audio isn't supported. <br />&nbsp; &lt;/audio&gt;&lt;br /&gt; <br />&nbsp; &lt;button id="mybutton"&gt;Change songs&lt;/button&gt; <br />&nbsp; &lt;script&gt; <br />&nbsp;&nbsp;&nbsp; // Handle the button click and play new file <br />&nbsp;&nbsp;&nbsp; document.getElementById("mybutton").addEventListener("click", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get audio object from audio element <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var oAudio = document.getElementById('myaudio'); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // double check support, and set the <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (oAudio) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.src = "nextaudioURL.mp4"; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.load(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.play(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp; }, false); <br />&nbsp; &lt;/script&gt; <br />&lt; /body&gt; <br />&lt; /html&gt;</span></p>
<p><span style="font-size: small;">That's pretty much all you need to do. Where code could get complex is in the song switching algorithm. </span></p>
<h3><span style="font-size: small;">A little more of a demo</span></h3>
<p><span style="font-size: small;">Here's a </span><a href="https://samples.msdn.microsoft.com/Workshop/samples/media/audio/audioJavascriptTest.html" target="_blank"><span style="font-size: small;">dressed up version</span></a><span style="font-size: small;"> of the original sample from </span><a href="https://msdn.microsoft.com/en-us/library/ie/gg589489(v=vs.85).aspx" target="_blank"><span style="font-size: small;">Using JavaScript to control the audio object</span></a><span style="font-size: small;">. </span></p>
<p><span style="font-family: Courier New;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/2783.audiojavascripttest_344FA9E3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/2783.audiojavascripttest_5F00_344FA9E3.png"><img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="audiojavascripttest" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/8640.audiojavascripttest_thumb_5AB18D2E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/8640.audiojavascripttest_5F00_thumb_5F00_5AB18D2E.png" alt="audiojavascripttest" width="597" height="234" border="0" /></a></span></p>
<p><span style="font-size: small;">Not much to look at, but you can choose between 5 songs, or load your own. The code is below.</span></p>
<p><span style="font-size: small;">The example has a simple UI that consists of an input field, a select box, and a few buttons. The songs are hard coded into the select box, with the text and URL for a song as a data pair on each option element. </span></p>
<p><span style="font-size: small;">All events are handled by addEventListeners in the JavaScript code. The play button calls play or pause, depending on its current state. The load method is called first if play is being called. </span></p>
<p><span style="font-size: small;">To switch the Play button label between "Play" and "Pause", we've added event listeners to the pause and play events, rather the play button code itself. This allows the button text&nbsp;to follow the actual state of the audio control. While the initial code doesn't expose the audio controls, you could add&nbsp;the intrinsic controls by adding the controls="controls" attribute to the audio element. The play&nbsp;button&nbsp;that switches labels would still&nbsp;stay in sync. </span></p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt; <br />&lt; html&gt; <br />&nbsp; <br />&nbsp; &lt;head&gt; <br />&nbsp;&nbsp;&nbsp; &lt;title&gt;HTML5 audio playlist demo &lt;/title&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;!-- Uncomment the following meta tag if you have issues rendering this page on an intranet site. --&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;!--&nbsp; &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"/&gt; --&gt;&nbsp; <br />&nbsp; &lt;/head&gt; <br />&nbsp; <br />&nbsp; &lt;body&gt; <br />&nbsp;&nbsp;&nbsp; &lt;h1&gt;Audio playlist demo&lt;/h1&gt; <br />&nbsp;&nbsp;&nbsp; &lt;p&gt;&lt;label&gt;Enter an audio file URL: <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="text" id="audiofile" size="80" /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/label&gt; <br />&nbsp;&nbsp;&nbsp; &lt;/p&gt; <br />&nbsp;&nbsp;&nbsp; &lt;p&gt;Or pick from this list:&lt;/p&gt; <br />&nbsp;&nbsp;&nbsp; &lt;select id="myselect"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value="<a href="https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Symphony_No_5_in_C_Minor_Op_67_-_I_Allegro_con_brio.mp3&quot;>Symphony">https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Symphony_No_5_in_C_Minor_Op_67_-_I_Allegro_con_brio.mp3"&gt;Symphony</a> No. 5 in C Minor, Op. 67 - I. Allegro con brio (Ludwig van Beethoven)&lt;/option&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value="<a href="https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Symphony_No_5_in_C_Minor_Op_67_-_II_Andante_con_moto.mp3&quot;>Symphony">https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Symphony_No_5_in_C_Minor_Op_67_-_II_Andante_con_moto.mp3"&gt;Symphony</a> No. 5 in C Minor, Op. 67 - II. Andante con moto (Ludwig van Beethoven)&lt;/option&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value="<a href="https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Symphony_No_5_in_C_Minor_Op_67_-_III_Allegro.mp3&quot;>Symphony">https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Symphony_No_5_in_C_Minor_Op_67_-_III_Allegro.mp3"&gt;Symphony</a> No. 5 in C Minor, Op. 67 - III. Allegro (Ludwig van Beethoven)&lt;/option&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value="<a href="https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Symphony_No_5_in_C_Minor_Op_67_-_IV_Allegro.mp3&quot;>Symphony">https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Symphony_No_5_in_C_Minor_Op_67_-_IV_Allegro.mp3"&gt;Symphony</a> No. 5 in C Minor, Op. 67 - IV. Allegro (Ludwig van Beethoven)&lt;/option&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value="<a href="https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Piano_Concerto_in_A_Minor_Op_16_-_I_Allegro_molto_moderato.mp3&quot;>Piano">https://samples.msdn.microsoft.com/Workshop/samples/media/Musopen_Com_Piano_Concerto_in_A_Minor_Op_16_-_I_Allegro_molto_moderato.mp3"&gt;Piano</a> Concerto in A Minor, Op. 16 - I. Allegro molto moderato (Edvard Grieg)&lt;/option&gt;</span><span style="font-family: Courier New;"> <br />&nbsp;&nbsp;&nbsp; &lt;/select&gt; <br />&nbsp;&nbsp;&nbsp; &lt;p&gt;All selections performed by Skidmore College Orchestra, available on <a href="https://musopen.org/.</p">https://musopen.org/.&lt;/p</a>&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; &lt;audio id="myaudio"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HTML5 audio not supported <br />&nbsp;&nbsp;&nbsp; &lt;/audio&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp; &lt;button id="play"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Play <br />&nbsp;&nbsp;&nbsp; &lt;/button&gt; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;button id="rewind"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Rewind <br />&nbsp;&nbsp;&nbsp; &lt;/button&gt; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;button id="forward"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fast forward <br />&nbsp;&nbsp;&nbsp; &lt;/button&gt; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;button id="restart"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Restart <br />&nbsp;&nbsp;&nbsp; &lt;/button&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp; &lt;script&gt; <br />&nbsp;&nbsp;&nbsp; // Global variable to track current file name. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var currentFile = ""; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var oAudio = document.getElementById('myaudio'); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var btn = document.getElementById('play'); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var audioURL = document.getElementById('audiofile'); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var mySelect = document.getElementById("myselect");</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById("play").addEventListener("click", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Check for audio element support. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (oAudio) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Tests the paused attribute and set state. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (oAudio.paused) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Skip loading if current file hasn't changed. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (audioURL.value !== "") { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (audioURL.value !== currentFile) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.src = audioURL.value; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; currentFile = audioURL.value; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.load(); // load the file <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var index = mySelect.selectedIndex; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var playThis = mySelect.options[index].value; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (playThis !== currentFile) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.src = playThis; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; currentFile = playThis; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.load(); // load the file <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.play(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.pause(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (e) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Fail silently but show in F12 developer tools console <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (window.console &amp;&amp; console.error("Error:" + e)); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // These two event listeners handle changing the play button from Pause to Play and back. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.addEventListener("pause", function () { btn.textContent = "Play"; }, false); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.addEventListener("play", function () { btn.textContent = "Pause"; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Rewinds the audio file by 30 seconds. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById("rewind").addEventListener("click", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (oAudio) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Check for audio element support. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.currentTime -= 30.0; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (e) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Fail silently but show in F12 developer tools console <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (window.console &amp;&amp; console.error("Error:" + e)); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Fast forwards the audio file by 30 seconds.</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById("forward").addEventListener("click", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (oAudio) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Check for audio element support.</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.currentTime += 30.0; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (e) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Fail silently but show in F12 developer tools console <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (window.console &amp;&amp; console.error("Error:" + e)); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Restart the audio file to the beginning. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById("restart").addEventListener("click", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (oAudio) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Check for audio element support. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.currentTime = 0; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (e) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Fail silently but show in F12 developer tools console <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (window.console &amp;&amp; console.error("Error:" + e)); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // On changing songs, pause video and call Play function again <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mySelect.addEventListener("change", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAudio.pause(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; btn.click(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false); <br />&nbsp;&nbsp;&nbsp; &lt;/script&gt; <br />&nbsp; &lt;/body&gt; <br />&lt; /html&gt;</span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Fill it even more! Creating a video fill pattern in canvas</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/fill-it-even-more-creating-a-video-fill-pattern-in-canvas</link>
      <pubDate>Fri, 21 Mar 2014 15:47:00 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/03/21/fill-it-even-more-creating-a-video-fill-pattern-in-canvas/</guid>
      <description><![CDATA[A&nbsp;recent comment left in the createPattern reference topic&nbsp;noted that&nbsp;while we talked...]]></description>
      <content:encoded><![CDATA[<p>A&nbsp;recent comment left in the <a href="https://msdn.microsoft.com/en-us/library/ie/ff975412(v=vs.85).aspx">createPattern</a> reference topic&nbsp;noted that&nbsp;while we talked about using a video for a fill pattern, we didn't show an example.&nbsp;&nbsp;That sounded like a pretty good idea, so here's what I came up with: <a href="https://go.microsoft.com/fwlink/p/?LinkID=392188" target="_blank">Video&nbsp; pattern sample</a>.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/4405.videopattern1_2DF3CB48.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/4405.videopattern1_5F00_2DF3CB48.png"><img style="margin: 3px auto; float: none; display: block; background-image: none;" title="videopattern1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/4428.videopattern1_thumb_3B59DE4E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/4428.videopattern1_5F00_thumb_5F00_3B59DE4E.png" alt="Image of canvas pattern with horizontal and vertical repeat" width="382" height="227" border="0" /></a></p>
<p>The video at the top is the original, and the canvas with the fill pattern is the big block below. The small video pattern is repeated in both the vertical and horizontal direction. If you run the video, you'll see that it all moves simultaneously. You can substitute an video file of your own, since this one isn't that action packed. <span style="color: #ff0000;">Note: You need to use a hosted .MP4 file<span style="color: #000000;">, not a random file from YouTube. For the most part, the URL you get in YouTube is a link to a page with an embedded video, not the video itself.</span></span></p>
<p align="center">&nbsp;</p>
<p align="center">You can set up fills to repeat vertically:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/6165.videopattern3_5E1DA6BC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/6165.videopattern3_5F00_5E1DA6BC.png"><img style="margin: 3px auto; float: none; display: block; background-image: none;" title="videopattern3" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/4011.videopattern3_thumb_04EBBCFD.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/4011.videopattern3_5F00_thumb_5F00_04EBBCFD.png" alt="Image of canvas pattern with vertical repeat" width="375" height="327" border="0" /></a></p>
<p align="center">&nbsp;</p>
<p align="center">or horizontally:</p>
<p align="center">&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/5100.videopattern2_64D0B03F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/5100.videopattern2_5F00_64D0B03F.png"><img style="margin: 3px auto; float: none; display: block; background-image: none;" title="videopattern2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/3056.videopattern2_thumb_76AD440C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/3056.videopattern2_5F00_thumb_5F00_76AD440C.png" alt="Image of canvas pattern with horizontal repeat" width="376" height="219" border="0" /></a></p>
<p align="center">Or not at all:</p>
<p align="center">&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/4527.videopattern4_6B83B9C2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/4527.videopattern4_5F00_6B83B9C2.png"><img style="margin: 3px auto; float: none; display: block; background-image: none;" title="videopattern4" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/0825.videopattern4_thumb_64647D4A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/0825.videopattern4_5F00_thumb_5F00_64647D4A.png" alt="Image of canvas pattern without any repeat" width="361" height="293" border="0" /></a></p>
<p>Picking how to repeat the pattern&nbsp;is up to you.</p>
<p>If you're familiar with using fills in Canvas, you're only a few steps away from filling with a video. A video fill is essentially a series of still frames swapped out as fast as the computer can do it. The result is a fill with full&nbsp;motion video. Here's how it works.</p>
<h3>Fill'r up, getting a shape filled</h3>
<p>For a quick refresher, <a href="https://samples.msdn.microsoft.com/Workshop/samples/canvas/simplerectfill.html" target="_blank">this example</a> shows how to fill a rectangle on a canvas.</p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt; <br /></span><span style="font-family: Courier New;">&lt;html&gt; <br />&lt; head&gt; <br />&nbsp; &lt;title&gt;Simple rectangle fill&lt;/title&gt;&nbsp; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp; &lt; canvas width="1080" height="800" id="myCanvas"&gt; <br />&nbsp;&nbsp;&nbsp; Sorry, canvas isn't supported in this browser or mode <br />&nbsp; &lt;/canvas&gt; <br />&nbsp; &lt;script&gt; <br />&nbsp;&nbsp;&nbsp; var canvas = document.getElementById("myCanvas"); <br />&nbsp;&nbsp;&nbsp; if(canvas.getContext){ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var ctx = canvas.getContext("2d");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fillStyle='red'; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fillRect(100, 100, 900, 600); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp; &lt;/script&gt; <br />&lt; /body&gt; <br />&lt; /html&gt;</span></p>
<h3>Picture a fill</h3>
<p>Now to do the same thing with an image. <a href="https://samples.msdn.microsoft.com/Workshop/samples/canvas/simplerectpatternfill.html" target="_blank">This code example</a> adds a pattern object using an image and&nbsp;the repetition direction. The original &lt;img&gt; element is hidden through a CSS style (display: none;).</p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt; <br />&lt;html&gt; <br />&lt; head&gt; <br />&nbsp; &lt;title&gt;Simple rectangle pattern fill&lt;/title&gt;&nbsp; <br />&nbsp; &lt;style&gt; <br />&nbsp;&nbsp;&nbsp; img { <br />&nbsp;&nbsp;&nbsp; display:none; <br />&nbsp;&nbsp;&nbsp; } <br />&nbsp; &lt;/style&gt; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp; &lt;canvas width="1080" height="800" id="myCanvas"&gt; <br />&nbsp;&nbsp;&nbsp; Sorry, canvas isn't supported in this browser or mode <br />&nbsp; &lt;/canvas&gt; <br />&nbsp; &lt; img id="pix" src="</span><a href="https://go.microsoft.com/fwlink/?LinkID=199028&quot;"><span style="font-family: Courier New;">https://go.microsoft.com/fwlink/?LinkID=199028"</span></a><span style="font-family: Courier New;"> /&gt; <br />&nbsp; &lt;script&gt; <br />&nbsp;&nbsp;&nbsp; var canvas = document.getElementById("myCanvas"); <br />&nbsp;&nbsp;&nbsp; if (canvas.getContext) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var image = document.getElementById("pix"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.addEventListener("load", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var ctx = canvas.getContext("2d"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var pattern = ctx.createPattern(image, "repeat"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fillStyle = pattern; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fillRect(100, 100, 900, 600); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp; &lt;/script&gt; <br />&lt; /body&gt; <br />&lt; /html&gt;</span></p>
<p>We added a couple of statements, the pattern object variable, an <a href="https://msdn.microsoft.com/en-us/library/ie/ms535259(v=vs.85).aspx" target="_blank">&lt;img&gt;</a> tag with a <a href="https://www.nasa.gov/multimedia/imagegallery/iotd.html">NASA image</a>, and a little CSS. The CSS simply turns off the display for the <a href="https://msdn.microsoft.com/en-us/library/ie/ms535259(v=vs.85).aspx" target="_blank">&lt;img&gt;</a> tag. In the JavaScript code, we get the image object of the hidden image. Using <a href="https://msdn.microsoft.com/en-us/library/ie/ff975412(v=vs.85).aspx">createPattern</a>, we&nbsp;create a pattern with a repetition of both horizontal and vertical.</p>
<p>We also captured the <a href="https://msdn.microsoft.com/en-us/library/ie/cc197055(v=vs.85).aspx">load</a> event for the image because the image is coming across time and space of the Internet, and might not be fully loaded into the &lt;img&gt; tag when we need it. Once <a href="https://msdn.microsoft.com/en-us/library/ie/cc197055(v=vs.85).aspx">load</a> fires, we then get the canvas context, and do the fill.</p>
<h3>Video, one frame at a time</h3>
<p>To create a video pattern, we swap out the <a href="https://msdn.microsoft.com/en-us/library/ie/ms535259(v=vs.85).aspx" target="_blank">&lt;img&gt;</a> tag with a <a href="https://msdn.microsoft.com/en-us/library/ie/hh772959(v=vs.85).aspx" target="_blank">&lt;video&gt;</a> tag. Using the same code as the image pattern but with the video element. It works, but only we just get a single video frame each time fill is called. In <a href="https://samples.msdn.microsoft.com/Workshop/samples/canvas/simplerectvideoframefill.html" target="_blank">this example</a>, try clicking the Show video frame button as the video changes.</p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt; <br />&lt; html&gt; <br />&lt; head&gt; <br />&nbsp; &lt;title&gt;Simple rectangle video frame fill&lt;/title&gt;&nbsp; <br />&nbsp; &lt;style&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp; video { <br />&nbsp;&nbsp;&nbsp; /*display:none;*/ <br />&nbsp;&nbsp;&nbsp; } <br />&nbsp; &lt;/style&gt; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp; <br />&nbsp; &lt;video id="myVideo" autoplay ="autoplay" controls="controls" width="200" height="160" src="</span><a href="https://ie.microsoft.com/testdrive/ieblog/2011/nov/pp4_blog_demo.mp4&quot;"><span style="font-family: Courier New;">https://ie.microsoft.com/testdrive/ieblog/2011/nov/pp4_blog_demo.mp4"</span></a><span style="font-family: Courier New;">&gt; <br />&nbsp;&nbsp;&nbsp; Sorry, video isn't supported in this browser or mode <br />&nbsp; &lt;/video&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp; &lt;button id="doVideo"&gt;Do video capture&lt;/button&gt;&lt;br /&gt; <br />&nbsp; &lt;canvas width="1080" height="800" id="myCanvas"&gt; <br />&nbsp;&nbsp;&nbsp; Sorry, canvas isn't supported in this browser or mode <br />&nbsp; &lt;/canvas&gt; <br />&nbsp; <br />&nbsp; &lt;script&gt; <br />&nbsp;&nbsp;&nbsp; document.getElementById("doVideo").addEventListener("click", fillVideo, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp; fillVideo();</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp; function fillVideo() { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var canvas = document.getElementById("myCanvas"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (canvas.getContext) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var video = document.getElementById("myVideo"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var ctx = canvas.getContext("2d"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var pattern = ctx.createPattern(video, "repeat"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fillStyle = pattern; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fillRect(100, 100, 900, 600); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp; } <br />&nbsp; &lt;/script&gt; <br />&lt; /body&gt; <br />&lt; /html&gt; <br /></span></p>
<p>Not very dynamic, as it only grabs a single video frame.</p>
<h3>Motion potion</h3>
<p>To&nbsp;create the magic of full motion video, we'll add an animation loop. We'll also add a button to start and stop the video, since the original video element is hidden in this demo. <a href="https://samples.msdn.microsoft.com/Workshop/samples/canvas/simpleRectVideoFill.html" target="_blank">This example</a> puts it all together.</p>
<p>&nbsp;</p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt; <br />&lt; html&gt; <br />&lt; head&gt; <br />&nbsp; &lt;title&gt;Simple rectangle video frame fill&lt;/title&gt;&nbsp; <br />&nbsp; &lt;style&gt; <br />&nbsp;&nbsp;&nbsp; video { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Turn off the original video element*/ <br />&nbsp;&nbsp;&nbsp; display:none; <br />&nbsp;&nbsp;&nbsp; } <br />&nbsp; &lt;/style&gt; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp; &lt;!-- Set up and play video --&gt; <br />&nbsp; &lt;video id="myVideo" autoplay ="autoplay" src="</span><a href="https://ie.microsoft.com/testdrive/ieblog/2011/nov/pp4_blog_demo.mp4&quot;"><span style="font-family: Courier New;">https://ie.microsoft.com/testdrive/ieblog/2011/nov/pp4_blog_demo.mp4"</span></a><span style="font-family: Courier New;">&gt; <br />&nbsp;&nbsp;&nbsp; Sorry, video isn't supported in this browser or mode <br />&nbsp; &lt;/video&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp; &lt;button id="stop"&gt;Stop video&lt;/button&gt;&lt;br /&gt; <br />&nbsp; &lt;canvas width="1280" height="800" id="myCanvas"&gt; <br />&nbsp;&nbsp;&nbsp; Sorry, canvas isn't supported in this browser or mode <br />&nbsp; &lt;/canvas&gt; <br />&nbsp; <br />&nbsp; &lt;script&gt; <br />&nbsp;&nbsp;&nbsp; var canvas = document.getElementById("myCanvas"); <br />&nbsp;&nbsp;&nbsp; if (canvas.getContext) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Canvas setup <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var ctx = canvas.getContext("2d"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var video = document.getElementById("myVideo"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var timerID; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var w = canvas.width; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var h = canvas.height;</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function animateVideo() {</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Stop loop when video ends <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (video.paused || video.ended) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Create a repeat video pattern <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pattern = ctx.createPattern(video, "repeat"); // Get the video frame&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fillStyle = pattern;&nbsp; // Assign pattern as a fill style. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fillRect(0, 0, w, h); // Fill the canvas. </span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Restart the animation <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timerID = window.requestAnimationFrame(animateVideo); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var button = document.getElementById("stop"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Start or stop video based on video state <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; button.addEventListener("click", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (video.paused) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video.play(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video.pause(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Change button text based on the video state <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video.addEventListener("pause", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; button.innerHTML = "Play"; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Change button text based on the video state, and start animation <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video.addEventListener("play", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; button.innerHTML = "Pause"; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; animateVideo(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false); <br />&nbsp;&nbsp;&nbsp; } <br />&nbsp; &lt;/script&gt; <br />&lt; /body&gt; <br />&lt; /html&gt;</span></p>
<p>We've added a couple of elements for ease of use. The button handler for video control&nbsp;has two independent parts. In the first part,&nbsp;the "click" event listener watches for a button&nbsp;press, and then&nbsp;checks to see if the video is <a href="https://msdn.microsoft.com/en-us/library/ie/ff974756(v=vs.85).aspx" target="_blank">paused</a> or not (the only two states we're interested in). If it's paused, it tells the video to <a href="https://msdn.microsoft.com/en-us/library/ie/ff975194(v=vs.85).aspx" target="_blank">play</a>. If not (else), it tells the video to <a href="https://msdn.microsoft.com/en-us/library/ie/ff975193(v=vs.85).aspx" target="_blank">pause</a>.</p>
<p>The second part&nbsp;has two event listeners that watch for the <a href="https://msdn.microsoft.com/en-us/library/ie/ff974160(v=vs.85).aspx" target="_blank">pause</a> and the <a href="https://msdn.microsoft.com/en-us/library/ie/ff974163(v=vs.85).aspx" target="_blank">play</a> events. If the pause event fires, it changes the button text to "Play." If the play event fires, it changes the button text to "Pause." We could have put the button changing code into the click event for the button, but&nbsp;run the risk of getting out of sync with the video. When the video starts (with <a href="https://msdn.microsoft.com/en-us/library/ie/ff974744(v=vs.85).aspx" target="_blank">autoplay</a>), the button&nbsp;might not have&nbsp;the&nbsp;correct label. When we capture the play and pause events, the button text change is independent of the video controls,. So whether we're pausing with the button or the video element (if displayed), it's still in sync.</p>
<h3>The secret sauce</h3>
<p>For&nbsp;full motion video display, we need to refresh the fill pattern more&nbsp;than just pressing a button like we did in the last example. This is accomplished using the <a href="https://msdn.microsoft.com/en-us/library/IE/hh773174(v=vs.85).aspx" target="_blank">requestAnimationFrame</a> method.</p>
<p>The <a href="https://msdn.microsoft.com/en-us/library/IE/hh773174(v=vs.85).aspx" target="_blank">requestAnimationFrame</a> method is the recommended way of getting accurate animation timing. Previously JavaScript coders used the <a href="https://msdn.microsoft.com/en-us/library/ie/ms536753(v=vs.85).aspx" target="_blank">setTimeout</a> method, which uses a fixed amount of time between frames. This&nbsp;works, but there are&nbsp;two problems. First, the UI might not be ready to render, so it skips frames&nbsp;(choppy animation). Second, when you leave the page, the animation is still running&nbsp;which eats up resources.</p>
<p>The <a href="https://msdn.microsoft.com/en-us/library/IE/hh773174(v=vs.85).aspx" target="_blank">requestAnimationFrame</a> method solves both these problems. RequestAnimationFrame&nbsp;asks the system to let us know when it's ok to draw an image. It never tries to do something when it can't, so there are no skipped frames. When you leave the page, the animation is suspended until you return to the page, so no resources are used.</p>
<p>In our example, we start the animation loop from within the play event. This ensures that the animation loop starts when the video is playing. If we put the call to animateVideo outside the loop, it might try to&nbsp;display the video before it's fully started, in which case it'll exit and never run again.</p>
<h3>Let's Play!</h3>
<p>One cool thing with patterns, video or otherwise, is that you don't need to have a rectangle for your patterns. This <a href="https://samples.msdn.microsoft.com/Workshop/samples/canvas/simpleRectVideoFill2.html">example</a> is a slight modification of the full motion video example. Rather than projecting into a rectangle, we're using a shape from an <a href="https://blogs.msdn.com/b/mediastuff/archive/2014/02/12/fill-r-up-please-the-canvas-msfillrule-api.aspx" target="_blank">earlier blog post</a>.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/1004.videostar_45CF9EFC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/1004.videostar_5F00_45CF9EFC.png"><img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="videostar" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/5545.videostar_thumb_657E78C4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/5545.videostar_5F00_thumb_5F00_657E78C4.png" alt="videostar" width="242" height="244" border="0" /></a></p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt; <br />&lt; html&gt; <br />&lt; head&gt; <br />&nbsp; &lt;title&gt;Simple rectangle video frame fill&lt;/title&gt;&nbsp; <br />&nbsp; &lt;style&gt; <br />&nbsp;&nbsp;&nbsp; video { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Turn off the original video element*/ <br />&nbsp;&nbsp;&nbsp; display:none; <br />&nbsp;&nbsp;&nbsp; } <br />&nbsp; &lt;/style&gt; <br />&lt; /head&gt; <br />&lt; body&gt; <br />&nbsp; &lt;!-- Set up and play video --&gt; <br />&nbsp; &lt;video id="myVideo" autoplay ="autoplay" src="</span><a href="https://ie.microsoft.com/testdrive/ieblog/2011/nov/pp4_blog_demo.mp4&quot;"><span style="font-family: Courier New;">https://ie.microsoft.com/testdrive/ieblog/2011/nov/pp4_blog_demo.mp4"</span></a><span style="font-family: Courier New;">&gt; <br />&nbsp;&nbsp;&nbsp; Sorry, video isn't supported in this browser or mode <br />&nbsp; &lt;/video&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp; &lt;button id="stop"&gt;Play&lt;/button&gt;&nbsp;&nbsp;&nbsp; &lt;button id="change"&gt;Change fill rule&lt;/button&gt; &lt;br /&gt; <br />&nbsp; &lt;canvas width="1280" height="800" id="myCanvas"&gt; <br />&nbsp;&nbsp;&nbsp; Sorry, canvas isn't supported in this browser or mode <br />&nbsp; &lt;/canvas&gt; <br />&nbsp; <br />&nbsp; &lt;script&gt; <br /></span> <br /><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp; var canvas = document.getElementById("myCanvas"); <br />&nbsp;&nbsp;&nbsp; if (canvas.getContext) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Canvas setup <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var ctx = canvas.getContext("2d"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var video = document.getElementById("myVideo"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var timerID; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var w = canvas.width; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var h = canvas.height;</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function animateVideo() {</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Stop loop when video ends <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (video.paused || video.ended) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Create a repeat video pattern <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pattern = ctx.createPattern(video, "repeat"); // Get the video frame&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear area for repeated use <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.beginPath(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.strokeStyle = 'blue'; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.lineWidth = "5" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.moveTo(200, 110); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.lineTo(50, 110); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.lineTo(300, 310); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.lineTo(200, 10); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.lineTo(100, 310); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.lineTo(350, 110); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.lineTo(200, 110); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.stroke(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fillStyle = pattern;&nbsp; // Assign pattern as a fill style.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.fill(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Restart the animation <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timerID = window.requestAnimationFrame(animateVideo); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var change = document.getElementById("change"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; change.addEventListener("click", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (ctx.msFillRule == "nonzero") { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.msFillRule = "evenodd"; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; change.innerHTML = "Change to non-zero"; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.msFillRule = "nonzero"; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; change.innerHTML = "Change to even-odd"; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var button = document.getElementById("stop"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Start or stop video based on video state <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; button.addEventListener("click", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (video.paused) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video.play(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video.pause(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Change button text based on the video state <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video.addEventListener("pause", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; button.innerHTML = "Play"; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Change button text based on the video state, and start animation <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video.addEventListener("play", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; button.innerHTML = "Pause"; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; animateVideo(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false); <br />&nbsp;&nbsp;&nbsp; } <br />&nbsp; &lt;/script&gt; <br />&lt; /body&gt; <br />&lt; /html&gt; <br /></span></p>
<p>Fun, right? Now with a little imagination, you can fill all kinds of things with video, circles, triangles, or even text.</p>
<p>Give it a try.</p>
<p>-Jay</p>]]></content:encoded>
    </item>
    <item>
      <title>Getting to Full Screen–using the fullscreen APIs.</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/getting-to-full-screenusing-the-fullscreen-apis</link>
      <pubDate>Fri, 14 Mar 2014 20:32:19 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/03/14/getting-to-full-screenusing-the-fullscreen-apis/</guid>
      <description><![CDATA[If you watch movies on Netflix or Amazon, you know how handy the full screen button can be. You can...]]></description>
      <content:encoded><![CDATA[<p>If you watch movies on Netflix or Amazon, you know how handy the full screen button can be. You can now build full screen capabilities into your apps with a couple of APIs and a few rules. </p>  <p>The full screen API is a collection of methods, properties, events and CSS elements that your app can use to control elements going full screen. It's a <a href="https://www.w3.org/TR/fullscreen/" target="_blank">W3C</a> and <a href="https://fullscreen.spec.whatwg.org/" target="_blank">WhatWG</a> standard. However the W3C spec is in working draft, and has been there since 2012, and the WhatWG spec, while it has a current date, pretty much looks the same. We might have to stick with the prefixes for a while.&#160;&#160; </p>  <p>This table shows the fullscreen API available in Internet Explorer 11. </p>  <table cellspacing="0" cellpadding="2" width="800" border="1"><tbody>     <tr>       <td valign="top" width="266">Member&#160; (W3C vesion)</td>        <td valign="top" width="100">Type</td>        <td valign="top" width="432">Description</td>     </tr>      <tr>       <td valign="top" width="266"><a href="https://msdn.microsoft.com/en-us/library/ie/dn254939(v=vs.85).aspx"><strong>msRequestFullscreen</strong></a> (requestFullscreen)</td>        <td valign="top" width="100">Method</td>        <td valign="top" width="432">Requests full-screen display of an image, video, or other element.</td>     </tr>      <tr>       <td valign="top" width="266"><a href="https://msdn.microsoft.com/en-us/library/ie/dn254936(v=vs.85).aspx"><strong>msExitFullscreen</strong></a> (exitFullscreen)</td>        <td valign="top" width="100">Method</td>        <td valign="top" width="432">Returns an element to its original size from full-screen mode. </td>     </tr>      <tr>       <td valign="top" width="266"><a href="https://msdn.microsoft.com/en-us/library/ie/dn254937(v=vs.85).aspx"><strong>msFullscreenElement</strong></a> (fullscreenElement)          <br /></td>        <td valign="top" width="100">Property</td>        <td valign="top" width="432">Returns the top or current element that's being displayed in full-screen mode. Otherwise it returns undefined.</td>     </tr>      <tr>       <td valign="top" width="266"><a href="https://msdn.microsoft.com/en-us/library/ie/dn254938(v=vs.85).aspx"><strong>msFullscreenEnabled</strong></a> (fullscreenEnabled)          <br /></td>        <td valign="top" width="100">Property</td>        <td valign="top" width="432">Returns true if a document lets elements be displayed in full-screen mode. Otherwise it returns false.</td>     </tr>      <tr>       <td valign="top" width="266"><a href="https://msdn.microsoft.com/en-us/library/ie/dn312066(v=vs.85).aspx"><strong>MSFullscreenChange</strong></a> (fullscreenChange)          <br /></td>        <td valign="top" width="100">Event</td>        <td valign="top" width="432">Fires when an element is displayed in full-screen mode, or when it exits full-screen mode. </td>     </tr>      <tr>       <td valign="top" width="266"><a href="https://msdn.microsoft.com/en-us/library/ie/dn312067(v=vs.85).aspx"><strong>MSFullscreenError</strong></a> (fullscreenError)          <br /></td>        <td valign="top" width="100">Event</td>        <td valign="top" width="432">Fires when a full-screen display is requested of an element, but this request can't be fulfilled.</td>     </tr>      <tr>       <td valign="top" width="266"><a href="https://msdn.microsoft.com/en-us/library/ie/dn312070(v=vs.85).aspx"><strong>allowfullscreen</strong></a> (same)          <br />          <br />&#160;</td>        <td valign="top" width="100">Attribute</td>        <td valign="top" width="432">Enables an iframe's content to display in full-screen mode. If missing, only the iframe (and not the content within the frame) can go to full-screen mode.</td>     </tr>      <tr>       <td valign="top" width="266">:<a href="https://msdn.microsoft.com/en-us/library/ie/dn312073(v=vs.85).aspx"><strong>-ms-fullscreen</strong></a> (:fullscreen)          <br /></td>        <td valign="top" width="100">Pseudo class</td>        <td valign="top" width="432">Enables you to set specific CSS properties based on whether an element is in full-screen mode or not. </td>     </tr>      <tr>       <td valign="top" width="266">::<a href="https://msdn.microsoft.com/en-us/library/ie/dn312072(v=vs.85).aspx"><strong>-ms-backdrop</strong></a> (::backdrop)</td>        <td valign="top" width="100">Pseudo element</td>        <td valign="top" width="432">Enables you to set the background properties when an element is displayed in full-screen mode. </td>     </tr>   </tbody></table>  <p>More info on these are available at <a href="https://msdn.microsoft.com/en-us/library/ie/dn265028(v=vs.85).aspx" target="_blank">Fullscreen API on MSDN</a>. </p>  <p>Here’s a <a href="https://samples.msdn.microsoft.com/Workshop/samples/media/fullscreen/fullscreendemo.html" target="_blank">simple example</a> that has three &lt;divs&gt;, an image, and a video element that you can click and make go full screen. It’s set up for Internet Explorer 11, Google Chrome, Mozilla Firefox, and Opera. Click any element to make it go full screen. Click the element a second time to exit full screen.</p>  <p>The example uses HTML classes to tag the elements that we want to make full screen. A simple loop runs on the collection of elements and creates click events which calls the makeFullFrame() function. The makeFullFrame function sorts out which prefixed version will work, and either requests full frame, or exits full frame. </p>  <p>All browsers have a way for the user to cancel full screen, as that’s one of the security items that the W3C spec calls out. However, I wanted a way to Initially I created separate full screen and exit full screen functions. Clicking the element made it full screen, and a button was supposed to exit full frame. The button used z-order to keep it on the top, but it turned out that didn't work because when you go to full frame, z-order is ignored. </p>  <p>While testing the makeFullFrame function to do double duty, I found I had to cancel bubbling on the click event. This was because anytime I clicked anything other than the first &lt;div&gt;, the click event would keep firing through all the child elements. Since all the elements are nested, that wouldn't work. The solution was to use stopPropagation() on the event on the first pass through. </p>  <p>The makeFullFrame function, other than testing for all the prefixed methods, also checks with the document object to see if an element is full screen. When any element is full screen in a page, the document.fullScreenElement attribute is set. Each browser has their own version of it, so we had to use prefixes there too. If the fullScreenElement is set, we then call the document.cancelFullScreen method. The W3C spec currently specifies exitFullscreen(), (IE uses msExitFullScreen), but the other browsers use a prefixed version of cancelFullscreen. </p>  <p>While each browser uses similar APIs, they don’t all behave the same. The W3C and WhatWG specs don't specify what elements expand to full screen, and which ones just block out the background. </p>  <p>This chart is the result of a quick test of the four browsers. Full screen means the element (img, div, or video) fills the screen completely. Same size means the element (div, img), stayed the same size as a normal view, but the background is blocked out.&#160; </p>  <blockquote>   <table cellspacing="0" cellpadding="2" width="800" border="1"><tbody>       <tr>         <td valign="top" width="160">Browser</td>          <td valign="top" width="160">&lt;div&gt;</td>          <td valign="top" width="160">&lt;img&gt;</td>          <td valign="top" width="160">&lt;video&gt;</td>          <td valign="top" width="160">click to exit</td>       </tr>        <tr>         <td valign="top" width="160">Internet Explorer</td>          <td valign="top" width="160">Same size</td>          <td valign="top" width="160">Full screen</td>          <td valign="top" width="160">Full screen </td>          <td valign="top" width="160">Yes</td>       </tr>        <tr>         <td valign="top" width="160">Chrome</td>          <td valign="top" width="160">Same size</td>          <td valign="top" width="160">Same size</td>          <td valign="top" width="160">Full screen</td>          <td valign="top" width="160">Yes</td>       </tr>        <tr>         <td valign="top" width="160">Firefox</td>          <td valign="top" width="160">Full screen</td>          <td valign="top" width="160">Full screen</td>          <td valign="top" width="160">Full screen</td>          <td valign="top" width="160">Yes but you must accept the Allow option.</td>       </tr>        <tr>         <td valign="top" width="160">Opera</td>          <td valign="top" width="160">Same size</td>          <td valign="top" width="160">Same size</td>          <td valign="top" width="160">Full screen</td>          <td valign="top" width="160">Yes except on video</td>       </tr>     </tbody></table> </blockquote>  <p>What’s interesting is that only Firefox expands a div to display full screen. All other browsers keep div elements the same size. One way around this (In Internet Explorer) is to use CSS and one of the new pseudo classes to fill the screen with the div (if that’s what you want). </p>  <p>Here’s how: </p>  <p><font face="Courier New">&lt;style&gt;</font></p>  <p><font face="Courier New">#test:-ms-fullscreen {      <br />&#160; position:absolute;       <br />&#160; left:0px;&#160;&#160; <br />&#160; top:0px;       <br />&#160; width: 100%;       <br />&#160; height: 100%;       <br />}</font></p>  <p><font face="Courier New">&lt;/style&gt;</font></p>  <p>Pretty slick, right? Another full screen pseudo element lets you either set a color or an image for the background for elements that don’t display edge to edge. Here’s how you call that one:</p>  <p><font face="Courier New">&lt;style&gt;</font></p>  <p><font face="Courier New">/* creates a background color of magenta */      <br />#test:-ms-fullscreen::-ms-backdrop {&#160; <br /></font><font face="Courier New">&#160;&#160; background-color: magenta;      <br />}</font></p>  <p><font face="Courier New">&lt;/style&gt;</font></p>  <p><font face="Courier New">&lt;style&gt;</font></p>  <p><font face="Courier New">/* creates a background image */      <br />#test:-ms-fullscreen::-ms-backdrop {&#160; <br /></font><font face="Courier New">&#160;&#160; background-image: url(&quot;image.jpg&quot;);&#160;&#160;&#160;&#160; <br />}</font></p>  <p><font face="Courier New">&lt;/style&gt;</font></p>  <p>When you view the example in Internet Explorer, you'll see a magenta background around the &lt;divs&gt;. You can modify the code to use a background-image as well. Unfortunately, not all browsers have jumped on the bandwagon for these two CSS pseudo goodies.&#160; </p>  <p>So that's the fullscreen API in a nutshell. Take a look at the reference pages (linked from the table above, and a <a href="https://msdn.microsoft.com/en-us/library/ie/dn265028(v=vs.85).aspx" target="_blank">conceptual piece</a> we did for IE11 launch. Note that the example is going under a facelift, since there were a bug or two in it. The following example is the &quot;new and improved&quot; version, and mirrors the <a href="https://samples.msdn.microsoft.com/Workshop/samples/media/fullscreen/fullscreendemo.html" target="_blank">online example</a>.</p>    <p><font face="Courier New">&lt;!DOCTYPE html&gt;     <br />&lt; html &gt;      <br />&lt; head&gt;      <br />&#160;&#160;&#160; &lt;title&gt;Fullscreen API test&lt;/title&gt;      <br />&#160;&#160;&#160; &lt;style&gt;      <br />&#160;&#160;&#160;&#160;&#160; video {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /* Push video element over */      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; position:relative;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; left: 350px;      <br />&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160; #div1 {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; background-color:green;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; width:800px;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; height:500px;      <br />&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160; #div2 {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; background-color:yellow;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; width:700px;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; height:400px;      <br />&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160; #div3 {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; background-color:red;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; width:300px;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; height:300px;      <br />&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160; div:-ms-fullscreen::-ms-backdrop {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; background-color:magenta;      <br />&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160; &lt;/style&gt;      <br />&#160; <br />&lt; /head&gt;      <br />&lt; body &gt;      <br />&#160; &lt;div id=&quot;div1&quot; class=&quot;fullScreen&quot; &gt; Div1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;div id=&quot;div2&quot; class=&quot;fullScreen&quot; &gt; Div2&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;video class=&quot;fullScreen&quot; controls=&quot;controls&quot; loop=&quot;loop&quot; autoplay=&quot;autoplay&quot; width=&quot;300&quot;&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;source src=&quot;demo.mp4&quot; type=&quot;video/mp4&quot; /&gt; &lt;!-- support for IE, Firefox, or Chrome --&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;source src=&quot;demo.ogv&quot; type=&quot;video/ogg&quot; /&gt;      <br />&lt; !--&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;source src=&quot;demo.webm&quot; type=&quot;video/webm&quot; /&gt;&#160; --&gt;&#160; &lt;!-- sample server doesn't like this --&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Sorry, video isn't supported      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt; /video&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;div id=&quot;div3&quot; class=&quot;fullScreen&quot; &gt; Div3      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt; img class=&quot;fullScreen&quot; src=&quot;image.jpg&quot;&#160; /&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/div&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/div&gt;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; &lt;/div&gt;      <br />&#160;&#160; &lt;script&gt;</font></p> <font face="Courier New"></font>  <p><font face="Courier New">&#160;&#160; // create click events for all the elements based on class.     <br />&#160;&#160; var fsClass = document.getElementsByClassName(&quot;fullScreen&quot;);      <br />&#160;&#160; for (var i = 0; i &lt; fsClass.length; i++) {      <br />&#160;&#160;&#160;&#160; fsClass[i].addEventListener(&quot;click&quot;, function (evt) { makeFullScreen(evt); }, false);&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160; }      <br />&#160;&#160;&#160; <br />&#160;&#160; function makeFullScreen(evt) {      <br />&#160;&#160;&#160;&#160;&#160; // Test for each of the supported versions of full screen APIs and call       <br />&#160;&#160;&#160;&#160; // either requestFullscreen or cancelFullScreen (or exitFullScreen)      <br />&#160;&#160;&#160;&#160; //&#160; Structure:       <br />&#160;&#160;&#160;&#160; //&#160; Does the incoming target support requestFullscreen (or prefaced version)      <br />&#160;&#160;&#160;&#160; //&#160; if (there is a fullscreen element)       <br />&#160;&#160;&#160;&#160; //&#160;&#160;&#160;&#160;&#160; then cancel or exit      <br />&#160;&#160;&#160;&#160; //&#160; else request full screen mode</font></p> <font face="Courier New"></font>  <p><font face="Courier New">&#160;&#160;&#160;&#160; var divObj = evt.target;&#160; //&#160; get the target element     <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160; if (divObj.requestFullscreen)&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160; if (document.fullScreenElement) {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; document.exitFullscreen();&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160; } else {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; divObj.requestFullscreen();      <br />&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160; else if (divObj.msRequestFullscreen)      <br />&#160;&#160;&#160;&#160;&#160;&#160; if (document.msFullscreenElement) {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; document.msExitFullscreen();      <br />&#160;&#160;&#160;&#160;&#160;&#160; } else {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; divObj.msRequestFullscreen();      <br />&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160; else if (divObj.mozRequestFullScreen)      <br />&#160;&#160;&#160;&#160;&#160;&#160; if (document.mozFullScreenElement) {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; document.mozCancelFullScreen();      <br />&#160;&#160;&#160;&#160;&#160; } else {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; divObj.mozRequestFullScreen();      <br />&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160; else if (divObj.webkitRequestFullscreen)      <br />&#160;&#160;&#160;&#160;&#160;&#160; if (document.webkitFullscreenElement) {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; document.webkitCancelFullScreen();      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; divObj.webkitRequestFullscreen();      <br />&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160; //&#160; stop bubbling so we don't get bounce back      <br />&#160;&#160;&#160;&#160;&#160; evt.stopPropagation();</font></p> <font face="Courier New"></font>  <p><font face="Courier New">&#160;&#160;&#160; }</font></p> <font face="Courier New"></font>  <p><font face="Courier New">&#160; &lt;/script&gt;     <br />&lt; /body&gt;      <br />&lt; /html&gt;      <br /></font></p>  <p>&#160;</p>  <p><font face="Courier New">&#160;</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Closed captioning, it’s not just for accessibility! TextTrack in HTML5 video</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/closed-captioning-its-not-just-for-accessibility-texttrack-in-html5-video</link>
      <pubDate>Wed, 05 Mar 2014 10:06:39 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/03/05/closed-captioning-its-not-just-for-accessibility-texttrack-in-html5-video/</guid>
      <description><![CDATA[When I hit the gym, I try to get a Stairmaster in front of a TV that&rsquo;s showing closed...]]></description>
      <content:encoded><![CDATA[<p>When I hit the gym, I try to get a Stairmaster in front of a TV that&rsquo;s showing closed captioning. Since I listen to music, I don&rsquo;t want to listen to the TV. With closed captioning, I can enjoy my music, and keep an eye on world events.</p>
<p>Closed captioning was originally conceived for hard of hearing viewers and offering programming in other languages without re-dubbing. Captioning can be a word for word transcription or translation of screen content, or it can be used for additional content like titles, locations, or commentary.</p>
<h2>The track element</h2>
<p>To add closed captioning, add a <a href="https://msdn.microsoft.com/en-us/library/hh772556(v=vs.85).aspx" target="_blank">track</a> element and point to a track file in your HTML5 video code. <a href="https://samples.msdn.microsoft.com/Workshop/samples/media/scriptingTrackElement/simpletrack.html" target="_blank">This example simply plays a video</a> with a track file.</p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt; <br />&lt;html&gt; <br />&nbsp; &lt;head&gt; <br />&nbsp; &lt;title&gt;Simple track example&lt;/title&gt; <br />&nbsp; &lt;/head&gt; <br />&nbsp; &lt;body&gt; <br />&nbsp;&nbsp;&nbsp; &lt;video id="video1" controls autoplay&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source src="</span><a href="https://ie.microsoft.com/testdrive/Videos/BehindIE9ModernWebStandards/Video.mp4&quot;"><span style="font-family: Courier New;">https://ie.microsoft.com/testdrive/Videos/BehindIE9ModernWebStandards/Video.mp4"</span></a><span style="font-family: Courier New;">&nbsp; &gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;track id='track1' label='English captions' src="entrack.vtt" kind='subtitles' srclang='en' default &gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;/video&gt; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp; &lt;/body&gt; <br />&lt;/html&gt;</span></p>
<p>Pretty cool, huh? Not a lot of extra code, just add the track element and you&rsquo;ve got closed captioning.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/4530.trackvideo_1C789527.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/4530.trackvideo_5F00_1C789527.png"><img style="display: inline; background-image: none;" title="trackvideo" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/4442.trackvideo_thumb_37B0EE28.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/4442.trackvideo_5F00_thumb_5F00_37B0EE28.png" alt="trackvideo" width="458" height="261" border="0" /></a></p>
<p>The built in controls that appear when you use the controls attribute on the video element lets you turn closed captioning on or off. If you&rsquo;ve got more than one track you can select between them as well.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/8255.multisubtitles_3091B1B0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/8255.multisubtitles_5F00_3091B1B0.png"><img style="display: inline; background-image: none;" title="multisubtitles" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/8267.multisubtitles_thumb_333A6D61.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/8267.multisubtitles_5F00_thumb_5F00_333A6D61.png" alt="multisubtitles" width="444" height="253" border="0" /></a></p>
<p>&nbsp;<a href="https://samples.msdn.microsoft.com/Workshop/samples/media/scriptingTrackElement/switchtracks.htm" target="_blank">Here&rsquo;s an example</a> of adding three translation tracks:</p>
<p><span style="font-family: Courier New;">&lt;video id="video1" controls autoplay loop&gt; <br />&nbsp; &lt; source src="video.mp4" type="video/mp4"&gt; <br />&nbsp; &lt;track id="enTrack" src="entrack.vtt" label="English" kind="subtitles" srclang="en" default&gt; <br />&nbsp; &lt;track id="esTrack" src="estrack.vtt" label="Spanish" kind="subtitles" srclang="es"&gt; <br />&nbsp; &lt;track id="deTrack" src="detrack.vtt" label="German" kind="subtitles" srclang="de"&gt; <br />&nbsp; HTML5 video not supported <br />&lt;/video&gt;</span></p>
<p>Inside the video element it&rsquo;s got a source element that points to the <a href="https://msdn.microsoft.com/en-us/library/hh772959(v=vs.85).aspx" target="_blank">video</a> file, and three <a href="https://msdn.microsoft.com/en-us/library/hh772556(v=vs.85).aspx" target="_blank">track</a> elements that point to track files. These tracks are written in WebVTT, a format for closed captioning. Lastly a message to display if HTML5 video isn&rsquo;t supported.</p>
<p>Internet Explorer supports two formats for closed captioning, WebVTT and TTML.</p>
<p>WebVTT is a reasonably simple format that provides the in and out timing points to insert text, and the text.</p>
<p><span style="font-family: Courier New;">WEBVTT</span></p>
<p><span style="font-family: Courier New;">00:00:01.878 --&gt; 00:00:05.334 <br /> Good day everyone, my name is John Smith</span></p>
<p><span style="font-family: Courier New;">00:00:08.608 --&gt; 00:00:15.296 <br /> This video will teach you how to <br /> build a sand castle on any beach</span></p>
<p>WebVTT has a few more features as outlined in the <a href="https://dev.w3.org/html5/webvtt/" target="_blank">W3C community group spec</a>, but not all are supported in IE.</p>
<p>The other format, TTML is an XML based format. A simple TTML file looks like this:</p>
<p><span style="font-family: Courier New;">&lt;?xml version='1.0' encoding='UTF-8'?&gt; <br />&lt;tt xmlns='</span><a href="https://www.w3.org/ns/ttml'"><span style="font-family: Courier New;">https://www.w3.org/ns/ttml'</span></a><span style="font-family: Courier New;"> xml:lang='en'&gt; <br />&lt;body&gt; <br />&lt;div&gt;</span></p>
<p><span style="font-family: Courier New;">&lt;p begin="00:00:01.878" end="00:00:05.334" &gt;Good day everyone, my name is John Smith&lt;/p&gt; <br />&lt;p begin="00:00:08.608" end="00:00:15.296" &gt;This video will teach you how to&lt;br/&gt;build a sand castle on any beach&lt;/p&gt; <br />&lt;/div&gt;</span></p>
<p><span style="font-family: Courier New;">&lt;/body&gt; <br />&lt;/tt&gt;</span></p>
<p>This is the original code that was supported in Internet Explorer 10. In IE11, support for <a href="https://msdn.microsoft.com/en-us/library/ie/dn265042(v=vs.85).aspx" target="_blank">Simple Delivery Profile (SDP)</a> caption styling was added. SDP gives some pretty cool abilities to place the text within the video frame, change text color, and background, and control stroke color and width. The full spec is here:</p>
<p><a href="https://www.w3.org/TR/ttml10-sdp-us/" target="_blank">TTML Simple Delivery Profile for Closed Captions (US)</a></p>
<p>The TTML gets a little more complicated, but it can really add power to your captioning.</p>
<p><span style="font-family: Courier New;">&lt;?xml version="1.0" encoding="utf-8"?&gt; <br />&lt;tt xml:lang="en-us" xmlns="</span><a href="https://www.w3.org/ns/ttml&quot;"><span style="font-family: Courier New;">https://www.w3.org/ns/ttml"</span></a><span style="font-family: Courier New;"> <br />&nbsp;&nbsp;&nbsp; xmlns:s="</span><a href="https://www.w3.org/ns/ttml#styling&quot;"><span style="font-family: Courier New;">https://www.w3.org/ns/ttml#styling"</span></a><span style="font-family: Courier New;"> <br />&nbsp;&nbsp;&nbsp; xmlns:p="</span><a href="https://www.w3.org/ns/ttml#parameter&quot;"><span style="font-family: Courier New;">https://www.w3.org/ns/ttml#parameter"</span></a><span style="font-family: Courier New;">&gt; <br />&nbsp; &lt;head&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;p:profile use="</span><a href="https://www.w3.org/ns/ttml/profile/sdp-us&quot;/"><span style="font-family: Courier New;">https://www.w3.org/ns/ttml/profile/sdp-us"/</span></a><span style="font-family: Courier New;">&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;styling&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- define styles for text color and position --&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;style xml:id="bottomMidStyle" s:textAlign="center" s:textOutline="red 1px" s:backgroundColor="#ff000044" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s:color="#ffffffff" s:origin='20% 78%' s:extent='30% 10%'/&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;style xml:id="topMidStyle" s:textAlign="center" s:textOutline="black 1px" s:backgroundColor="#00ff0088" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s:color="#ff11ffff" s:origin='20% 40%' s:extent='60% 18%'/&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;style xml:id="topLeftStyle" s:textAlign="left" s:textOutline="blue 1px" s:backgroundColor="transparent" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s:color="#ff11ffff" s:origin='10% 10%' s:extent='30% 10%'/&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;style xml:id="bottomRightStyle" s:textAlign="right" s:textOutline="black 1px" s:backgroundColor="white" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s:color="green" s:origin='70% 70%' s:extent='30% 10%'/&gt; <br />&nbsp;&nbsp;&nbsp; &lt;/styling&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp; &lt;layout&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- define regions for locating text --&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;region xml:id="bottomMid" style='bottomMidStyle' /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;region xml:id="topMid" style='topMidStyle' /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;region xml:id="topLeft" style='topLeftStyle' /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;region xml:id="bottomRight" style='bottomRightStyle' /&gt; <br />&nbsp;&nbsp;&nbsp; &lt;/layout&gt; <br />&nbsp; &lt;/head&gt; <br />&nbsp; &lt;body&gt; <br />&nbsp;&nbsp;&nbsp; &lt;div style='defaultFont'&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p region="bottomMid" begin='00:00:00.101' end='00:00:05.000'&gt; This is a Pop-up caption&lt;/p&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p region="topMid" begin='00:00:05.000' end='00:00:10.000'&gt; This is another Pop-up caption&lt;/p&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p region="topLeft" begin='00:00:10.000' end='00:00:15.000'&gt; Hello from up top&lt;/p&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p region="bottomRight" begin='00:00:15.000' end='00:00:20.000'&gt; And back down&lt;/p&gt; <br />&nbsp;&nbsp; &lt;/div&gt; <br />&nbsp; &lt;/body&gt; <br />&lt;/tt&gt;</span></p>
<p>Using SDP is no different than plain captioning:</p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html&gt; <br />&lt;html&gt; <br />&nbsp;&nbsp;&nbsp; &lt;head&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;title&gt;SDP Test&lt;/title&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;/head&gt; <br />&nbsp;&nbsp;&nbsp; &lt;body&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;video src="video.mp4" controls muted autoplay width="800"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;track src="SDPTest.ttml" label="SDP Examples" default/&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/video&gt; <br />&nbsp;&nbsp;&nbsp; &lt;/body&gt; <br />&lt;/html&gt;</span></p>
<p>That&rsquo;s it.</p>
<p>Adding code for supporting a track file is not very hard. However, you do need to work a little to create the .vtt or .ttml file. To make that a little easier, check out <a href="https://samples.msdn.microsoft.com/Workshop/samples/media/captionmaker/default.html" target="_blank">HTML5 Video Caption Maker</a>.&nbsp; How to use Caption Maker and more on Text Track is described in <a href="https://msdn.microsoft.com/en-us/library/jj152143(v=vs.85).aspx" target="_blank">Make your videos accessible with Timed Text Tracks</a>.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/7510.captionmaker_2C1B30E9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/7510.captionmaker_5F00_2C1B30E9.png"><img style="display: inline; background-image: none;" title="captionmaker" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/63/48/metablogapi/8171.captionmaker_thumb_24FBF471.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-63-48-metablogapi/8171.captionmaker_5F00_thumb_5F00_24FBF471.png" alt="captionmaker" width="732" height="517" border="0" /></a></p>
<p>Caption Maker lets you load a video file and step through it, typing or pasting in captions or comments. Try it first with the Load Sample button. This loads up an MP4 file to play with. Once the video is loaded, you get the option to load a sample VTT file. You can load or save WebVTT or TTML format files.&nbsp;</p>
<p>Caption Maker was written in the IE10 timeframe, so it doesn&rsquo;t support SDP, but it creates a good starting point. It only takes MP4 files, and not OGG or WebM. If you use IE10 or IE11, run Caption Maker, and press F12. You&rsquo;ll be able to download the various files to experiment yourself.</p>
<h2>Using track for other cool stuff</h2>
<p>I teased it in the title, but you can get pretty creative by using JavaScript to fetch cues (captions) from your tracks. <a href="https://msdn.microsoft.com/en-us/library/jj152145(v=vs.85).aspx" target="_blank">This article</a> outlines in the series described above shows you some of the script things you can do. One thing is to created your own styled text. Since you can overlay a text field onto a video element, you can place text anywhere you want and style it with CSS. To be sure text lines up correctly, you&rsquo;ll have to use the CSS position attribute. Once you have your layout, that&rsquo;s not that hard.</p>
<p><a href="https://samples.msdn.microsoft.com/Workshop/samples/media/scriptingTrackElement/cuechange2a.html" target="_blank">This example uses the &ldquo;metadata&rdquo;</a> as the kind of track. When you specify the track in HTML, you set the <span style="font-family: Courier New;">kind=</span> attribute. Typically you set it to captions or subtitles, so the video element takes care of displaying the track text. However, by changing that to &ldquo;metadata&rdquo;, you now can get cues in JavaScript, but they don&rsquo;t display on the screen. <a href="https://samples.msdn.microsoft.com/Workshop/samples/media/scriptingTrackElement/cuechange2a.html" target="_blank">Here&rsquo;s some code</a> that takes captions and puts them in color (with the much hated Comic Sans font) at the top of the video element.</p>
<p><span style="font-family: Courier New;">&lt;!DOCTYPE html &gt; <br />&lt;html&gt; <br />&nbsp; &lt;head&gt; <br />&nbsp; &lt;title&gt;Styled text example&lt;/title&gt; <br />&nbsp;&nbsp;&nbsp; &lt;!-- only force Internet Explorer 10 standards for testing on local machine --&gt; <br />&nbsp; &lt;style&gt; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; #display <br />&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; position:absolute;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; display:block;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text-align :center; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color:yellow; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-size:24px; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-family:Comic Sans MS; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text-shadow: 0.1em 0.1em 0.15em #333; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; z-index:100; /* set z-index to be sure div is on top */ <br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp; &lt;/style&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp; &lt;/head&gt; <br />&nbsp; &lt;body&gt; <br />&nbsp;&nbsp;&nbsp; &lt;div id="player" style='width:640px;'&gt; &lt;!-- container div that is sized by script --&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;video id="video1" controls style='width:100%;'&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source src="</span><a href="https://ie.microsoft.com/testdrive/Videos/BehindIE9ModernWebStandards/Video.mp4&quot;"><span style="font-family: Courier New;">https://ie.microsoft.com/testdrive/Videos/BehindIE9ModernWebStandards/Video.mp4"</span></a><span style="font-family: Courier New;">&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- by using "metadata" as the kind, it will suppress the video player's own caption display --&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;track id="track1" label="English captions" src="entrack.vtt" kind="metadata" srclang="en" default&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/video&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div id="display"&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;/div&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;/div&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp; &lt;script&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var video; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; get objects associated with the video, track, and div elements&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video = document.getElementById("video1"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var disp = document.getElementById("display"); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var track = document.getElementById("track1");</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; video.addEventListener("loadedmetadata", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById("player").style.width = video.videoWidth + "px";&nbsp; // make enclosure div width == video width <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; disp.style.top = (video.style.top + (video.videoHeight * .05)) + "px"; // set the text to appear at 5% from the top of the video <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; disp.style.left = video.style.left;&nbsp; // set the text to appear relative to the left edge of the video <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; disp.style.width = video.videoWidth + "px"; // set text box to the width of the video <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; track.addEventListener("cuechange", function () { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var myTrack = this.track;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // track element is "this" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var myCues = myTrack.activeCues;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // activeCues is an array of current cues.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (myCues.length &gt; 0) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; disp.innerText = myCues[0].text;&nbsp;&nbsp; // write the text <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, false);</span></p>
<p><span style="font-family: Courier New;">&nbsp;&nbsp;&nbsp; &lt;/script&gt;</span></p>
<p><span style="font-family: Courier New;">&nbsp; &lt;/body&gt; <br />&lt;/html&gt;</span></p>
<p>&nbsp;<a href="https://samples.msdn.microsoft.com/Workshop/samples/media/scriptingTrackElement/TrackSlideShow.htm" target="_blank">In this example</a>, the metadata cues are a series of URLs synced to the video. When the guy shows the IE Testdrive site, you see the live site on the screen. This one is a little contrived, but you get the idea.</p>
<p>So that&rsquo;s all there is to add accessibility and other cool features to your online videos. Give it a try.</p>]]></content:encoded>
    </item>
    <item>
      <title>Video streaming without plug-ins or special servers</title>
      <link>https://docs.microsoft.com/archive/blogs/mediastuff/video-streaming-without-plug-ins-or-special-servers</link>
      <pubDate>Wed, 19 Feb 2014 12:08:00 GMT</pubDate>
      <dc:creator><![CDATA[jay munro-[Ex-MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mediastuff/2014/02/19/video-streaming-without-plug-ins-or-special-servers/</guid>
      <description><![CDATA[I&rsquo;ve been covering mostly canvas so far here, but I recently finished a sample and article in...]]></description>
      <content:encoded><![CDATA[<p>I&rsquo;ve been covering mostly canvas so far here, but I recently finished a sample and article in the media area. It&rsquo;s on how to create a simple MPEG-DASH streaming player. The cool thing about DASH is that you don&rsquo;t need plug-ins on your client, and you serve the content from a standard issue HTTP server. No fancy server required.</p>
<p>The code uses the Media Source Extension API, and DASH files created with MP4Box, a packaging utility. There are a growing number of HTML5 and MSE based players showing how to do streaming. MSE lets you stream video to your page by substituting a buffer or buffers for a URL on the src property of a video element. Most of the samples I found on the web used a whole bunch of little files with segments of the video.</p>
<p>I read that you could also use a single segmented file. Using XMLHTTPRequest (XHR) and setRequestHeader with byte ranges,&nbsp; you can get small chunks of video from a single video file. I heard it, but didn&rsquo;t find a good example.. I&rsquo;d always wanted to try out XHR and ranges, so I created a sample that uses MSE with a single file.</p>
<p>The <a href="https://msdn.microsoft.com/en-us/library/dn551369(v=vs.85).aspx" target="_blank">article</a> has two sections, <a href="https://msdn.microsoft.com/en-us/library/dn551368(v=vs.85).aspx" target="_blank">building the sample</a>, and a <a href="https://msdn.microsoft.com/en-us/library/dn551370(v=vs.85).aspx" target="_blank">resource reference</a> page. There&rsquo;s also a <a href="https://samples.msdn.microsoft.com/Workshop/samples/media/mpdParseExample.html" target="_blank">working example</a> to try it out. Note that the example only runs in IE11. It loads in Chrome, but I think it's having difficulty with the MP4 support.</p>
<p>Take a look and check out the article. Let me know what you think.</p>
<p><img title="Screen shot of Simple MPEG-DASH player." src="https://msdnstage/dynimg/IC710520.png" alt="Screen shot of Simple MPEG-DASH player." /></p>
<p>-Jay</p>
<h2>Update:</h2>
<p>I've rewritten the article and uploaded it to <a href="https://docs.webplatform.org/wiki/tutorials/MSEPrimer" target="_blank">webplatform.org,</a> and with the help of Renior at webplatform.org, uploaded the example. You can now play with the <a href="https://code.webplatform.org/gist/9144919/" target="_blank">code in real time</a> in the Dabblet environment. There are a few changes, fewer &lt;divs&gt;, and the video is stored locally on webplatform.org.</p>
<p>Enjoy.</p>]]></content:encoded>
    </item>
  </channel>
</rss>