Introduction
The solution described here allows to embed video hosted on YouTube into SharePoint. The same approach may be applied for embedding video from another video hosting sites, for example from Vimeo.
The main idea here to store embedded video properties and not the embedded code itself.
For storing embedded video properties we will use Custom List, see implementation section for description. Page for Video Links list (default view with embedded player) is shown below
Usage
In order to embed a video into SharePoint:
- On YouTube site click the Share button located under the video.
- Click the Embed button.
- Copy at least src attribute value provided in the expanded box (see table 1 for supported attributes).
- Create new Video Link item and paste attribute values for embedded code into Video Links item. Save it.
Table 1. Mapping between embedded code iframe attributes and Video Link item
Attribute name | Video Links field name |
---|---|
src | URL |
width | Video Width |
height | Video Height |
allowfullscreen | Allow Fullscreen |
frameborder | Frame Border |
Video Links implementation
As was mentioned earlier only properties for embedded video code are stored and not the embedded code itself. For storing embedded video code properties is used Custom List that extends OOB Links List (TemplateType = 103)
For embedded video properties we create Video Link Content Type that inherits from Link CT (0x0105)
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
<?xml version="1.0" encoding="utf-8"?> | |
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> | |
<!– Parent ContentType: Link (0x0105) –> | |
<ContentType ID="0x010501" | |
Name="Video Link" | |
Group="$Resources:List_Content_Types" | |
Description="Video Link Content Type" | |
Inherits="TRUE" | |
Version="0"> | |
<FieldRefs> | |
<FieldRef ID="{594e551f-180d-47ec-90e5-9195225c5932}" Name="FrameBorder" Required="FALSE" /> | |
<FieldRef ID="{a1e94df1-eb6e-4fd2-aef7-bf0cc175c760}" Name="VideoHeight" Required="FALSE" /> | |
<FieldRef ID="{e0406eee-7432-47d8-9080-8c1c4db23170}" Name="VideoWidth" Required="FALSE" /> | |
<FieldRef ID="{b6ba6c8f-81d6-478a-a303-3b18687ec934}" Name="AllowFullScreen" Required="FALSE" /> | |
<FieldRef ID="{5836ef4c-c440-4cb8-a471-0ee918bfc710}" Name="EmbeddingMode" Required="FALSE" /> | |
<FieldRef ID="{C1D8C50A-2146-41f6-80CC-02C7691392A3}" Name="EmbeddedVideoOnForm" /> | |
</FieldRefs> | |
</ContentType> | |
</Elements> |
where we define the following fields
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
<?xml version="1.0" encoding="utf-8"?> | |
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> | |
<Field Type="Number" | |
DisplayName="Frame Border" | |
Required="FALSE" | |
EnforceUniqueValues="FALSE" | |
Group="Media Columns" | |
ID="{594e551f-180d-47ec-90e5-9195225c5932}" | |
StaticName="FrameBorder" | |
Name="FrameBorder" | |
Percentage="FALSE" | |
Hidden="FALSE" | |
SourceID="http://schemas.microsoft.com/sharepoint/v3"> | |
<Default>0</Default> | |
</Field> | |
<Field Type="Number" | |
DisplayName="Video Height" | |
Required="FALSE" | |
EnforceUniqueValues="FALSE" | |
Group="Media Columns" | |
ID="{a1e94df1-eb6e-4fd2-aef7-bf0cc175c760}" | |
StaticName="VideoHeight" | |
Name="VideoHeight" | |
Percentage="FALSE" | |
Hidden="FALSE" | |
SourceID="http://schemas.microsoft.com/sharepoint/v3"/> | |
<Field Type="Number" | |
DisplayName="Video Width" | |
Required="FALSE" | |
EnforceUniqueValues="FALSE" | |
Group="Media Columns" | |
ID="{e0406eee-7432-47d8-9080-8c1c4db23170}" | |
StaticName="VideoWidth" | |
Name="VideoWidth" | |
Percentage="FALSE" | |
Hidden="FALSE" | |
SourceID="http://schemas.microsoft.com/sharepoint/v3"/> | |
<Field Type="Boolean" | |
DisplayName="Allow FullScreen" | |
EnforceUniqueValues="FALSE" | |
Group="Media Columns" | |
ID="{b6ba6c8f-81d6-478a-a303-3b18687ec934}" | |
StaticName="AllowFullScreen" | |
Name="AllowFullScreen" | |
Required="FALSE" | |
Hidden="FALSE" | |
SourceID="http://schemas.microsoft.com/sharepoint/v3"> | |
<Default>0</Default> | |
</Field> | |
<Field Type="Choice" | |
DisplayName="Embedding Mode" | |
Required="FALSE" | |
EnforceUniqueValues="FALSE" | |
Format="Dropdown" | |
FillInChoice="FALSE" | |
Group="Media Columns" | |
ID="{5836ef4c-c440-4cb8-a471-0ee918bfc710}" | |
StaticName="EmbeddingMode" | |
Name="EmbeddingMode" | |
Hidden="FALSE" | |
SourceID="http://schemas.microsoft.com/sharepoint/v3"> | |
<Default>IFrame</Default> | |
<CHOICES> | |
<CHOICE>IFrame</CHOICE> | |
<CHOICE>Object</CHOICE> | |
</CHOICES> | |
</Field> | |
<Field | |
ID="{C1D8C50A-2146-41f6-80CC-02C7691392A3}" | |
Type="Computed" | |
Name="EmbeddedVideoOnForm" | |
StaticName="EmbeddedVideoOnForm" | |
DisplaceOnUpgrade="TRUE" | |
ShowInNewForm="FALSE" | |
ShowInDisplayForm="FALSE" | |
ShowInEditForm="FALSE" | |
ShowInFileDlg="FALSE" | |
DisplayName="Embedded Video" | |
SourceID="http://schemas.microsoft.com/sharepoint/v3/fields" | |
Sealed="TRUE" | |
Sortable="FALSE" | |
Filterable="FALSE"> | |
<FieldRefs> | |
<FieldRef Name="URL" /> | |
<FieldRef Name="FileLeafRef" /> | |
<FieldRef Name="FileRef" /> | |
<FieldRef Name="FSObjType" /> | |
<FieldRef Name="EmbeddingMode" /> | |
<FieldRef Name="VideoWidth" /> | |
<FieldRef Name="VideoHeight" /> | |
<FieldRef Name="FrameBorder" /> | |
</FieldRefs> | |
<DisplayPattern> | |
<IfEqual> | |
<Expr1> | |
<Column Name="EmbeddingMode" /> | |
</Expr1> | |
<Expr2>IFrame</Expr2> | |
<Then> | |
<HTML><![CDATA[<iframe width=']]></HTML> | |
<Field Name="VideoWidth"/> | |
<HTML><![CDATA[' height=']]></HTML> | |
<Field Name="VideoHeight"/> | |
<HTML><![CDATA[' src=']]></HTML> | |
<Field Name="URL"/> | |
<HTML><![CDATA[' frameborder=']]></HTML> | |
<Field Name="FrameBorder"/> | |
<HTML><![CDATA[' allowfullscreen']]></HTML> | |
<HTML> | |
<![CDATA['></iframe>]]> | |
</HTML> | |
</Then> | |
<Else> | |
<HTML> | |
<![CDATA[Not supported yet]]> | |
</HTML> | |
</Else> | |
</IfEqual> | |
</DisplayPattern> | |
</Field> | |
</Elements> |
Pay attention, for rendering YouTube player Computed Field EmbeddedVideoOnForm is intended.
For rendering of a field on a List View the following XSLT style sheet is used
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
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"> | |
<xsl:template match ="FieldRef[@Name='EmbeddedVideoOnForm']" mode="Computed_body" > | |
<xsl:param name="thisNode" select="."/> | |
<xsl:variable name="width"> | |
<xsl:call-template name="ensureVideoPlayerSize"> | |
<xsl:with-param name="videoSize" select="$thisNode/@VideoWidth"/> | |
<xsl:with-param name="defaultSize" select="560"/> | |
</xsl:call-template> | |
</xsl:variable> | |
<xsl:variable name="height"> | |
<xsl:call-template name="ensureVideoPlayerSize"> | |
<xsl:with-param name="videoSize" select="$thisNode/@VideoHeight"/> | |
<xsl:with-param name="defaultSize" select="315"/> | |
</xsl:call-template> | |
</xsl:variable> | |
<xsl:variable name="frameborder"> | |
<xsl:value-of select="$thisNode/@FrameBorder"/> | |
</xsl:variable> | |
<xsl:variable name="src"> | |
<xsl:value-of select="$thisNode/@URL"/> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$thisNode/@EmbeddingMode ='IFrame'"> | |
<iframe width="{$width}" height="{$height}" src="{$src}" frameborder="{$frameborder}" allowfullscreen=""></iframe> | |
</xsl:when> | |
<xsl:otherwise> | |
<div>Not supported yet</div> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="ensureVideoPlayerSize"> | |
<xsl:param name="videoSize"/> | |
<xsl:param name="defaultSize"/> | |
<xsl:choose> | |
<xsl:when test="$videoSize > 0"> | |
<xsl:value-of select="$videoSize"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$defaultSize"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> |
And finally, we create List Definition Video Links from Content Type Video Link. List schema and Template files for Video Links including whole project may be found on GitHub.
Nice implementation !!! A couple of month i created the same solution called cloud media SharePoint Extenstion which can be found on codeplex http://cmse.codeplex.com. My solution grabs the meta data directrly form vimeo and youtube and add it to a asset library in case you are interested in.
Hi Stefan, thank you for mention of your solution! I am really interested to see it.
Would be great if you could tell me what you think about. Maybe join the forces.
Pingback: Embedding and Sharing Video in SharePoint. Part Two: Posting embedded code, support for different Video Providers, Preview view | vgrem's Blog
Pingback: Embedding and Sharing Video in SharePoint. Part Three: Aggregating Video Feeds and utilizing API | vgrem's Blog
Pingback: Embedding Video to a SharePoint Library | Yet Another SharePoint Blog