protected void Page_Load(object sender, EventArgs e) { //available querystring values for context info (id, language, version, database) try { //get the current item and database currentDB = Sitecore.Configuration.Factory.GetDatabase("master"); currentItem = new PlayerItem(currentDB.Items[HttpContext.Current.Request.QueryString["id"].ToString()]); Item acct = currentItem.playerItem.Parent.Parent; //if current parent isn't the account then it's the parent of the folder if (!acct.TemplateName.Equals("Account Folder")) { acct = acct.Parent; } accountItem = new AccountItem(acct.ID, acct.InnerData, acct.Database); bc = new BCAPI(accountItem.PublisherID); //populate drop down if (!IsPostBack) { foreach (Item itm in accountItem.Parent.ChildByTemplateAndName("Settings Folder", "Settings").ChildByTemplateAndName("Enum", "WMode").GetChildren()) { ddlWMode.Items.Add(new ListItem(itm.DisplayName, itm.DisplayName)); } //fill player drop down foreach (VideoItem vp in accountItem.VideoLib.Videos) { ddlVideo.Items.Add(new ListItem(vp.VideoName, vp.videoItem.ID.ToString())); } //fill playlist drop down foreach (PlaylistItem pl in accountItem.PlaylistLib.Playlists) { cblPlaylist.Items.Add(new ListItem(pl.PlaylistName, pl.playlistItem.ID.ToString())); } if (!currentItem.PlaylistType.Equals(PlayerPlaylistType.None) && cblPlaylist.Items.Count > 0) { cblPlaylist.SelectedIndex = 0; } //set the initial player up if (ddlVideo.Items.Count > 0) { SetVideoPlayer(); } else { ltlMessage.Text = "To use the preview section you must have already defined at least one player"; } } } catch(Exception ex){ ltlError.Text = ex.ToString(); } }
/// <summary> /// this makes sure you've selected an item from the video treeview /// </summary> /// <param name="sender"></param> /// <param name="args"></param> protected override void OnOK(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); //get the selected playlist Item player = masterDB.Items[PlayerTreeview.Value]; if (player == null || !player.TemplateName.Equals(Constants.PlayerTemplate)) { SheerResponse.Alert("Select a player.", new string[0]); return; } //get the selected video Item video = masterDB.Items[VideoTreeview.Value]; string videoid = ""; if (video != null && video.TemplateName.Equals(Constants.VideoTemplate)) { VideoItem vid = new VideoItem(video); videoid = vid.VideoID.ToString(); } //get the selected playlists Item[] playlists = this.PlaylistTreeview.GetSelectedItems(); PlayerItem vpl = new PlayerItem(player); //set the playlists StringBuilder playlistStr = new StringBuilder(); int plistCount = 0; foreach (Item p in playlists) { if (p.TemplateName.Equals(Constants.PlaylistTemplate)) { PlaylistItem pl = new PlaylistItem(p); if (playlistStr.Length > 0) { playlistStr.Append(","); } playlistStr.Append(pl.PlaylistID.ToString()); plistCount++; } } //check if the player can handle the playlists selected if (vpl.PlaylistType.Equals(PlayerPlaylistType.None) && plistCount > 0) { SheerResponse.Alert("This player does not support playlists.\nTo deselect, select the Brightcove Media item.", new string[0]); return; } else if (vpl.PlaylistType.Equals(PlayerPlaylistType.VideoList) && plistCount > 1) { SheerResponse.Alert("This player only supports one playlist.", new string[0]); return; } else if ((vpl.PlaylistType.Equals(PlayerPlaylistType.VideoList) || vpl.PlaylistType.Equals(PlayerPlaylistType.ComboBox) || vpl.PlaylistType.Equals(PlayerPlaylistType.Tabbed)) && !videoid.Equals("")) { SheerResponse.Alert("This player does not support videos. \nTo deselect, select the Brightcove Media item.", new string[0]); return; } //build link then send it back StringBuilder mediaUrl = new StringBuilder(); mediaUrl.Append("<bc:VideoPlayerWebControl runat=\"server\" class=\"BrightcoveVideo\" xmlns:bc=\"http://www.sitecore.net/xhtml\" "); mediaUrl.Append("player=\"" + vpl.PlayerID + "\" "); mediaUrl.Append("autostart=\"" + chkAutoStart.Checked.ToString().ToLower() + "\" "); mediaUrl.Append("bgcolor=\"" + txtBGColor.Value + "\" "); mediaUrl.Append("wmode=\"" + WMode.SelectedItem.Header + "\" "); //determine what kind of playlist if (vpl.PlaylistType.Equals(PlayerPlaylistType.ComboBox)) { mediaUrl.Append("playlistcombo=\"" + playlistStr.ToString() + "\" "); }else if (vpl.PlaylistType.Equals(PlayerPlaylistType.Tabbed)){ mediaUrl.Append("playlisttabs=\"" + playlistStr.ToString() + "\" "); }else if (vpl.PlaylistType.Equals(PlayerPlaylistType.VideoList)){ mediaUrl.Append("videolist=\"" + playlistStr.ToString() + "\" "); }else if (vpl.PlaylistType.Equals(PlayerPlaylistType.None)){ mediaUrl.Append("video =\"" + videoid + "\" "); } //close the tag mediaUrl.Append("></bc:VideoPlayer>"); //send it back if (this.Mode == "webedit") { SheerResponse.SetDialogValue(StringUtil.EscapeJavascriptString(mediaUrl.ToString())); base.OnOK(sender, args); } else { SheerResponse.Eval("scClose(" + StringUtil.EscapeJavascriptString(mediaUrl.ToString()) + "," + StringUtil.EscapeJavascriptString(player.DisplayName) + ")"); } }
/// <summary> /// this makes sure you've selected an item from the video treeview /// </summary> /// <param name="sender"></param> /// <param name="args"></param> protected override void OnOK(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); //get the selected player Item player = masterDB.Items[PlayerTreeview.Value]; if (player == null || !player.TemplateName.Equals(Constants.PlayerTemplate)) { SheerResponse.Alert("Select a player.", new string[0]); return; } PlayerItem vpl = new PlayerItem(player); //get the selected video Item video = masterDB.Items[VideoTreeview.Value]; VideoItem vid = null; string videoid = ""; if (video != null && video.TemplateName.Equals(Constants.VideoTemplate)) { vid = new VideoItem(video); videoid = vid.VideoID.ToString(); } //get the selected playlists Item[] playlists = this.PlaylistTreeview.GetSelectedItems(); //set the playlists StringBuilder playlistStr = new StringBuilder(); int plistCount = 0; foreach (Item p in playlists) { if (p.TemplateName.Equals(Constants.PlaylistTemplate)) { PlaylistItem pl = new PlaylistItem(p); if (playlistStr.Length > 0) { playlistStr.Append(","); } playlistStr.Append(pl.PlaylistID.ToString()); plistCount++; } } //check if the player can handle the playlists selected if (vpl.PlaylistType.Equals(PlayerPlaylistType.None) && plistCount > 0) { SheerResponse.Alert("This player does not support playlists.\nTo deselect, select the Brightcove Media item.", new string[0]); return; } else if (vpl.PlaylistType.Equals(PlayerPlaylistType.VideoList) && plistCount > 1) { SheerResponse.Alert("This player only supports one playlist.", new string[0]); return; } else if ((vpl.PlaylistType.Equals(PlayerPlaylistType.VideoList) || vpl.PlaylistType.Equals(PlayerPlaylistType.ComboBox) || vpl.PlaylistType.Equals(PlayerPlaylistType.Tabbed)) && !videoid.Equals("")) { SheerResponse.Alert("This player does not support videos. \nTo deselect, select the Brightcove Media item.", new string[0]); return; } //use settings to determine what kind of modal window to use like thickbox or prettyphoto //id = {3EE8D1E1-1421-4546-8127-4D576FB8DA5F} ModalLinkSettings settings = ModalLinkSettings.GetModalLinkSettings(HttpContext.Current.Request.Url.Host.ToLower(), masterDB); StringBuilder sbAttr = new StringBuilder(); StringBuilder sbQstring = new StringBuilder(); if (settings != null) { foreach(Item child in settings.thisItem.GetChildren()){ if(child.TemplateName.Equals(Constants.LinkAttributeTemplate)){ sbAttr.Append(" " + child["Key"] + "=\"" + child["Value"] + "\""); } else if(child.TemplateName.Equals(Constants.LinkQuerystringTemplate)){ sbQstring.Append("&" + child["Key"] + "=" + child["Value"]); } } } //build link then send it back StringBuilder mediaUrl = new StringBuilder(); mediaUrl.Append("<a href=\"/BrightcoveVideo.ashx?video=" + videoid + "&player=" + vpl.PlayerID); mediaUrl.Append("&playlists=" + playlistStr.ToString()); mediaUrl.Append("&autoStart=" + chkAutoStart.Checked.ToString().ToLower()); mediaUrl.Append("&bgcolor=" + txtBGColor.Value.Replace("#", "")); mediaUrl.Append("&wmode=" + WMode.SelectedItem.Header); mediaUrl.Append("&oparams=" + txtOParams.Value); mediaUrl.Append(sbQstring.ToString()); mediaUrl.Append("&height=" + (vpl.Height + 20).ToString() + "&width=" + (vpl.Width + 20).ToString() + "\"" + sbAttr.ToString() + " title=\"" + txtLinkText.Value + "\">" + txtLinkText.Value + "</a>"); if (this.Mode == "webedit") { SheerResponse.SetDialogValue(StringUtil.EscapeJavascriptString(mediaUrl.ToString())); base.OnOK(sender, args); } else { SheerResponse.Eval("scCloseLink(" + StringUtil.EscapeJavascriptString(mediaUrl.ToString()) + ")"); } }