Created
January 10, 2011 08:54
-
-
Save dariuszparys/772552 to your computer and use it in GitHub Desktop.
WebMatrix HTML5 Video Tag Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@functions { | |
private static bool IsParam(string parameter) | |
{ | |
if( !string.IsNullOrEmpty( parameter ) ) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
} | |
@helper CreateAlternateDownloadLinks(string prefix, | |
string wmvUrl = "", | |
string mp4Url = "", | |
string webmUrl = "", | |
string oggUrl = "") | |
{ | |
if( IsParam( wmvUrl ) ) | |
{ | |
@AlternateDownloadLink( wmvUrl, prefix + " wmv") | |
} | |
if( IsParam( mp4Url ) ) | |
{ | |
@AlternateDownloadLink( mp4Url, prefix + " mp4" ) | |
} | |
if( IsParam( webmUrl ) ) | |
{ | |
@AlternateDownloadLink( webmUrl, prefix + " webm") | |
} | |
if( IsParam( oggUrl ) ) | |
{ | |
@AlternateDownloadLink( oggUrl, prefix + " ogg") | |
} | |
} | |
@helper AlternateDownloadLink(string url, string text) | |
{ | |
<a href="@url">@text</a> | |
} | |
@helper Create( string wmvUrl = "", | |
string mp4Url = "", | |
string webmUrl = "", | |
string oggUrl = "", | |
int width = 400, | |
int height = 250, | |
string poster = "", | |
string silverlightPlayerXapUrl = "", | |
string silverlightPlayerInitParams = "", | |
string flashPlayerUrl = "", | |
string flashPlayerVars = "", | |
string alternateDownloadPrefixText = "" | |
) | |
{ | |
<video id="video" width="@width" height="@height" preload controls poster="@poster"> | |
@if( IsParam( wmvUrl ) ) | |
{ | |
<source src="@wmvUrl"/> | |
} | |
@if( IsParam( mp4Url ) ) | |
{ | |
<source src="@mp4Url" type="video/mp4"/> | |
} | |
@if( IsParam( webmUrl ) ) | |
{ | |
<source src="@webmUrl" type="video/webm" codecs="vp8, vorbis"/> | |
} | |
@if( IsParam( oggUrl ) ) | |
{ | |
<source src="@oggUrl" type="video/ogg" codecs="theora, vorbis"/> | |
} | |
@if( IsParam( silverlightPlayerXapUrl ) && IsParam( silverlightPlayerInitParams ) ) | |
{ | |
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="@width" height="@height"> | |
<param name="source" value="@silverlightPlayerXapUrl" /> | |
<param name="initParams" value="@silverlightPlayerInitParams" /> | |
<param name="background" value="#00FFFFFF" /> | |
<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"> | |
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/> | |
</a> | |
</object> | |
} | |
@if( IsParam( flashPlayerUrl ) && IsParam( flashPlayerVars ) ) | |
{ | |
<object width="@width" height="@height" type="application/x-shockware-flash" data="@flashPlayerUrl"> | |
<param name="movie" value="@flashPlayerUrl"/> | |
<param name="allowfullscreen" value="true"/> | |
<param name="flashvars" value="@flashPlayerVars"/> | |
</object> | |
} | |
@if( IsParam( alternateDownloadPrefixText ) ) | |
{ | |
<div id="alternate-download-links"> | |
@CreateAlternateDownloadLinks(alternateDownloadPrefixText, wmvUrl, mp4Url, webmUrl, oggUrl) | |
</div> | |
} | |
</video> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment