2015-07-12

In the previous post, we saw some of the technical details of the Office 365 Video / PointPublishing site. We all know that the Office 365 videos can be embedded into the another site by embedding the Iframe.

Example:

<iframe width=640 height=360 
src='https://<tenant>.sharepoint.com/portals/hub/_layouts/15/VideoEmbedHost.aspx?chId=b6c48249%2Dcd8a%2D43e9%2Dbb94%2D7df7e8303033&amp;vId=bd9e2f2a%2D10b6%2D49fb%2Db6c0%2D774731f0bb7e&amp;width=640&amp;height=360&amp;autoPlay=false&amp;showInfo=true' 
allowfullscreen></iframe>

The above html can be retrieved from the video page by clicking the embed link.

Here we will see how to access a video from the Azure media service uploaded from the Office 365 site and play it using the Azure Media Player. “Azure Media Player utilizes industry standards, such as HTML5, Media Source Extensions (MSE) and Encrypted Media Extensions (EME) to provide an enriched adaptive streaming experience. When these standards are not available on a device or in a browser, Azure Media Player uses Flash and Silverlight as fallback technology.”

Before looking into the Azure Media Player implementation, we will look into some of the details of the “VideoEmbed.aspx” displays the Office 365 video.

  • Takes the ChannelId and VideoId as a query string parameter.
  • Gets the Azure Media Video Url.
    • Request: “http://<tenant>/portals/hub/_api/videoservice/Channels(guid’b6c48249-cd8a-43e9-bb94-7df7e8303033′)/Videos(guid’bd9e2f2a-10b6-49fb-b6c0-774731f0bb7e’)/GetPlaybackUrl(1)
    • GET
    • Response:
    {  
       "d":{  
          "GetPlaybackUrl":"https://cdn-cvpram202m01.streaming.mediaservices.windows.net/5304be04-c003-4b37-88eb-32da0b207344/a79ae230-e3a9-471d-9ac7-ff2d17a6acb0.ism/Manifest"
       }
    }
  • Gets the Access Token to access the Video stored in the Azure media for streaming.
    • Request: “http://<tenant>/portals/hub/_api/videoservice/Channels(guid’b6c48249-cd8a-43e9-bb94-7df7e8303033′)/Videos(guid’bd9e2f2a-10b6-49fb-b6c0-774731f0bb7e’)/GetStreamingKeyAccessToken”
    • GET
    • Response:
    {  
       "d":{  
          "GetStreamingKeyAccessToken":"Bearer=urn%3amicrosoft%3aazure%3amediaservices%3acontentkeyidentifier=4d0300f2-bd5b-4b43-b8f2-ce1b9464686c&urn%3amicrosoft%3aazure%3amediaservices%3akeyacquisitionhostname=cvpram202m01.keydelivery.mediaservices.windows.net&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fnimbuslkgglobacs.accesscontrol.windows.net&urn%3aServiceAccessible=service&Audience=urn%3aNimbus&ExpiresOn=1436713660&Issuer=https%3a%2f%2fnimbuslkgglobacs.accesscontrol.windows.net%2f&HMACSHA256=Iz6HyLoB%2bknTuOOdzXqnVQ2t6dM%2fp9Y4a0EM3q8PNdo%3d"      <br>
       }
    }
  • Initialise the Video Player. (Uses the Azure Media Player)
  • Sends an signal to record that the video is viewed.
    • Request: http://<tenant>/portals/hub/_api/signalstore/signals
    • POST
    VALID JSON (RFC 4627)
    Formatted JSON Data
    {  
       "signals":[  
          {  
             "Actor":{  
                "Id":null
             },
             "Action":{  
                "ActionType":"ViewedVideo",
                "UserTime":"2015-07-12T15:06:04.051Z",
                "Properties":{  
                   "results":[  
    
                   ]
                }
             },
             "Item":{  
                "Id":"https://<tenant>.sharepoint.com/portals/BBC/pVid/Forms/DispForm.aspx?ID=7",
                "Properties":{  
                   "results":[  
    
                   ]
                }
             },
             "Source":"PointVideo"
          }
       ]
    }
  • Increments the Video view count.
    • Request: http://<tenant>/portals/hub/_api/videoservice/Channels(guid’b6c48249-cd8a-43e9-bb94-7df7e8303033′)/Videos(guid’bd9e2f2a-10b6-49fb-b6c0-774731f0bb7e’)/IncrementViewCount
    • POST

So now, we will see how to implement the above using the custom Azure Media Player within a SharePoint page.

  • Embed the HTML5 video element with the reference to the Azure Media Player script.
<!--*****START OF Azure Media Player Scripts*****--><script type="text/javascript" src="//amp.azure.net/libs/amp/latest/azuremediaplayer.min.js"></script>
<link href="//amp.azure.net/libs/amp/latest/skins/amp-default/azuremediaplayer.min.css" rel="stylesheet">
<!-- Set the location of the fallback techs -->
<script type="text/javascript">
   amp.options.flashSS.swf = "//amp.azure.net/libs/amp/latest/techs/StrobeMediaPlayback.2.0.swf";
   
   amp.options.flashSS.plugin = "//amp.azure.net/libs/amp/latest/techs/MSAdaptiveStreamingPlugin-osmf2.0.swf";
   
   amp.options.silverlightSS.xap = "//amp.azure.net/libs/amp/latest/techs/SmoothStreamingPlayer.xap";
   
</script>
<!--*****END OF Azure Media Player Scripts*****-->
<video id="azuremediaplayer" class="azuremediaplayer amp-default-skin amp-big-play-centered" controls autoplay width="640" height="400" poster="" data-setup='{"nativeControlsForTouch": false}' tabindex="0">
   <p class="amp-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video</p>
</video>
  • Embed / Call the below script to Initialise the Video player.
function InitialiseVideo() {
    var spVideoUrl = "/portals/BBC/pVid/IMG_1779.MOV";
    GetAzureMediaUrl(spVideoUrl).then(
        function(responseMediaUrl) {
 
            return GetAzureMediaAccessToken(spVideoUrl).then(
                function(responseAccessToken) {
                    var azureMediaUrl = JSON.parse(responseMediaUrl.body).value;
                    var azureMediaAccessToken = JSON.parse(responseAccessToken.body).value;
                    SetAzureMediaPlayer(azureMediaUrl, azureMediaAccessToken);
                }
            );
        }
    );
}
 
function GetAzureMediaUrl(spVideoUrl) {
 
    var deferred = $.Deferred();
    var executor = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl);
    executor.executeAsync({
        url: "https://tenant.sharepoint.com/portals/hub/_api/VideoService/GetVideoByUrl('" + spVideoUrl + "')/getplaybackurl(1)",
        method: "GET",
        headers: {
            "Accept": "application/json; odata=nometadata"
        },
        success: function(data) {
            deferred.resolve(data);
        },
        error: function(data, errorCode, errorMessage) {
            deferred.reject(data, errorCode, errorMessage);
        }
    });
 
    return deferred.promise();
}
 
function GetAzureMediaAccessToken(spVideoUrl) {
 
    var deferred = $.Deferred();
    var executor = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl);
    executor.executeAsync({
        url: "https://tenant.sharepoint.com/portals/hub/_api/VideoService/GetVideoByUrl('" + spVideoUrl + "')/GetStreamingKeyAccessToken",
        method: "GET",
        headers: {
            "Accept": "application/json; odata=nometadata"
        },
        success: function(data) {
            deferred.resolve(data);
        },
        error: function(data, errorCode, errorMessage) {
            deferred.reject(data, errorCode, errorMessage);
        }
    });
 
    return deferred.promise();
}
 
function SetAzureMediaPlayer(azureMediaUrl, azureMediaAccessToken) {
    var myOptions = {
        "nativeControlsForTouch": false,
        autoplay: false,
        controls: true,
        width: "640",
        height: "400",
        poster: ""
    };
    var myPlayer = amp("azuremediaplayer", myOptions);
 
    myPlayer.src[{
        src: azureMediaUrl,
        type: "application/vnd.ms-sstr+xml",
        protectionInfo: [{
            type: "AES",
            authenticationToken: azureMediaAccessToken
        }]
    }]);
}
 
var scriptbase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js",
    function() {
        $.getScript(scriptbase + "SP.js",
            function() {
                $.getScript(scriptbase + "SP.RequestExecutor.js", InitialiseVideo);
            }
        );
    }
);
  • Screenshot:

Note: The above script uses the Office 365 Video Url (instead of the channel and video id’s) to access the Azure Media and Initialise the Azure Media Player with the Azure Media Url and the Azure Media Player can be extended to call the other APIs using the event listeners.

About the author 

Balamurugan Kailasam