In this blog we will see how to bind video from remote server using web part properties. Recently I faced an issue that big (more than 500 MB) videos are not playing properly or sometimes it shows only blank screen from SharePoint library.
After discussing it with the team we found the below solution. For this I have placed video in apache sever and fetched the video from server. I have done this using visual web part in SharePoint. After binding link in web part properties it gets that video from server.
Below are the steps that I have performed.
- Open visual stuido using run as Administrator mode -> Click on file -> add new project -> give name to the project -> after creation of project -> right click to to the project -> add new item -> select visual web part.
- Open .ascx file and add below code into it
- <style>
- .VideoDiv {
- margin: 0px auto;
- width: 500px;
- }
-
- .pVideo {
- width: 500px;
- }
- </style>
- <div class="VideoDiv" id="VideoDiv" runat="server"> </div>
- Open .ascx.cs file and add below code into it.
- public string IndiaURL {
- get;
- set;
- }
- public string PosterURL {
- get;
- set;
- }
- protected void Page_Load(object sender, EventArgs e) {
- string FullIpAddress = string.Empty;
- FullIpAddress = GetLanIPAddress().Replace("::ffff:", "");
- string[] split = FullIpAddress.Split('.');
- StringBuilder VideoStrBuilder = new StringBuilder();
- VideoStrBuilder.Append("<video poster='" + PosterURL + "' src='" + IndiaURL + "' controls='true' class='pVideo'>");
- VideoStrBuilder.Append("</video>");
- VideoDiv.InnerHtml = VideoStrBuilder.ToString();
- }
-
-
-
- public String GetLanIPAddress() {
-
-
- String ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
- if (string.IsNullOrEmpty(ip)) {
- ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
- }
- return ip;
- }
- Open .cs file and add below code in to class
-
- private
- const string _ascxPath = @ "~/_CONTROLTEMPLATES/15/Project/Videos/VideosUserControl.ascx";
- [Personalizable(PersonalizationScope.Shared)]
- [WebBrowsable(true)]
- [Category("Custom Property")]
- [WebDisplayName("India URL")]
- [Description("India Video Server URL")]
- public string ProIndUrl {
- get;
- set;
- }
- [Personalizable(PersonalizationScope.Shared)]
- [WebBrowsable(true)]
- [Category("Custom Property")]
- [WebDisplayName("Poster URL")]
- [Description("Video Poster URL")]
- public string ProPosterURL {
- get;
- set;
- }
- protected override void CreateChildControls() {
-
- var control = (VideosUserControl) Page.LoadControl(_ascxPath);
- control.IndiaURL = ProIndUrl;
- control.PosterURL = ProPosterURL;
- Controls.Add(control);
- }
- Build and check for errors if no error is found then deploy the project.
- Create one web part page and above web part into it
- Now edit the web part set the remote server url and give path of that video.
- Save it and you will see that video plays quickly as compares to SharePoint document library
Thank you.