Example #1
0
        private void LoadSettings()
        {
            thePlayer = MediaPlayer.GetForModule(moduleId);
            theTrack = MediaTrack.Get(trackId);

            // need to enforce that the track is connected to the player that is connected to the module instance
            if ((theTrack == null) || (thePlayer == null) || (theTrack.PlayerId != thePlayer.PlayerId))
            {
                // url manipulation hard redirect to current page
                Response.Redirect(SiteUtils.GetCurrentPageUrl(), true);
            }

            FilesObjectDataSource.SelectParameters.Add("trackID", TypeCode.Int32, theTrack.TrackId.ToInvariantString());

            if (thePlayer.PlayerType == MediaType.Audio)
            {
                MediaFileBrowser.BrowserType = "audio";
            }

            if (thePlayer.PlayerType == MediaType.Video)
            {
                MediaFileBrowser.BrowserType = "video";
            }
        }
Example #2
0
        public static bool Update(MediaPlayer mediaPlayer)
        {
            //Get the current persisted MediaPlayer
            MediaPlayer currentPlayer = Get(mediaPlayer.PlayerId);

            //Update the MediaPlayer
            bool isUpdated = DBMediaPlayer.Update(
                mediaPlayer.PlayerId,
                mediaPlayer.ModuleId,
                mediaPlayer.PlayerType.ToString(),
                mediaPlayer.SkinName,
                mediaPlayer.UserGuid,
                mediaPlayer.ModuleGuid);

            //If the MediaPlayer is successfully updated, update the associated MediaTracks.
            if (isUpdated)
            {
                //Remove any MediaTracks that no longer exist.
                foreach (MediaTrack currentTrack in currentPlayer.MediaTracks)
                {
                    bool matchFound = false;
                    foreach (MediaTrack updatedTrack in mediaPlayer.MediaTracks)
                    {
                        if (currentTrack.TrackId == updatedTrack.TrackId)
                        {
                            matchFound = true;
                            break;
                        }
                    }

                    if (!matchFound)
                    {
                        MediaTrack.Remove(currentTrack);
                    }
                }

                //Add any MediaTracks that have not been persisted yet.
                foreach (MediaTrack updatedTrack in mediaPlayer.MediaTracks)
                {
                    if (updatedTrack.TrackId <= 0)
                    {
                        updatedTrack.TrackId = MediaTrack.Add(updatedTrack);
                    }
                }
            }

            return isUpdated;
        }
Example #3
0
        /// <summary>
        /// Creates a list of MediaPlayers from an IDataReader populated with Media Player data.
        /// </summary>
        /// <param name="reader">The IDataReader.</param>
        /// <returns>A List of MediaPlayers.</returns>
        private static List<MediaPlayer> LoadListFromReader(IDataReader reader)
        {
            List<MediaPlayer> playerList = new List<MediaPlayer>();

            try
            {
                while (reader.Read())
                {
                    MediaPlayer player = new MediaPlayer();
                    player.PlayerId = Convert.ToInt32(reader["PlayerID"]);
                    player.ModuleId = Convert.ToInt32(reader["ModuleID"]);
                    player.PlayerType = (MediaType)Enum.Parse(typeof(MediaType), reader["PlayerType"].ToString());
                    player.SkinName = reader["Skin"].ToString();
                    player.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]);
                    player.UserGuid = new Guid(reader["UserGuid"].ToString());
                    player.ModuleGuid = new Guid(reader["ModuleGuid"].ToString());
                    playerList.Add(player);
                }
            }
            finally
            {
                reader.Close();
            }

            return playerList;
        }
Example #4
0
        /// <summary>
        /// Adds a Media Player.
        /// </summary>
        /// <param name="mediaPlayer">The MediaPlayer.</param>
        /// <returns>The ID of the MediaPlayer.</returns>
        public static int Add(MediaPlayer mediaPlayer)
        {
            //Insert the MediaPlayer.
            int playerId = DBMediaPlayer.Insert(
                mediaPlayer.ModuleId,
                mediaPlayer.PlayerType.ToString(),
                mediaPlayer.SkinName,
                mediaPlayer.UserGuid,
                mediaPlayer.ModuleGuid);

            mediaPlayer.playerId = playerId;

            //Insert each of the MediaPlayer's MediaTracks.
            foreach (MediaTrack track in mediaPlayer.MediaTracks)
            {
                track.PlayerId = playerId;
                MediaTrack.Add(track);
            }

            return playerId;
        }
        /// <summary>
        /// Loads needed settings from their repository.
        /// </summary>
        private void LoadSettings()
        {
            //Load the player.
            thePlayer = MediaPlayer.GetForModule(ModuleId);
            if (thePlayer == null)
            {
                thePlayer = new MediaPlayer();
                thePlayer.ModuleGuid = ModuleGuid;
                thePlayer.ModuleId = ModuleId;
                thePlayer.PlayerType = MediaType.Audio;
                if (IsEditable)
                {
                    SiteUser currentUser = SiteUtils.GetCurrentSiteUser();
                    if (currentUser != null)
                    {
                        thePlayer.UserGuid = currentUser.UserGuid;
                        MediaPlayer.Add(thePlayer);
                    }
                }
            }

            config = new AudioPlayerConfiguration(Settings);

            if (config.DisableShuffle)
            {
                ShuffleControl.Visible = false;
                ShuffleOffControl.Visible = false;
            }

            if (config.InstanceCssClass.Length > 0)
            {
                pnlOuterWrap.SetOrAppendCss(config.InstanceCssClass);
            }
        }
        /// <summary>
        /// Loads needed settings from their repository.
        /// </summary>
        private void LoadSettings()
        {
            //siteRoot = WebUtils.GetSiteRoot();
            //if (SiteUtils.IsSecureRequest())
            //{
            //    siteRoot = siteRoot.Replace("http:", "https:");
            //}
            //Load the player.
            thePlayer = MediaPlayer.GetForModule(ModuleId);
            if (thePlayer == null)
            {
                thePlayer = new MediaPlayer();
                thePlayer.ModuleGuid = ModuleGuid;
                thePlayer.ModuleId = ModuleId;
                thePlayer.PlayerType = MediaType.Video;
                if (IsEditable)
                {
                    SiteUser currentUser = SiteUtils.GetCurrentSiteUser();
                    if (currentUser != null)
                    {
                        thePlayer.UserGuid = currentUser.UserGuid;
                        MediaPlayer.Add(thePlayer);
                    }
                }
            }

            config = new VideoPlayerConfiguration(Settings);

            if (config.DisableShuffle)
            {
                ShuffleControl.Visible = false;
                ShuffleOffControl.Visible = false;
            }

            if (config.InstanceCssClass.Length > 0)
            {
                pnlOuterWrap.SetOrAppendCss(config.InstanceCssClass);
            }
        }
Example #7
0
        private void LoadParams()
        {
            //Get the PageId and ModuleId from the QueryString
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", moduleId);

            thePlayer = MediaPlayer.GetForModule(moduleId);

            if (thePlayer == null)
            {
                Response.Redirect(SiteUtils.GetCurrentPageUrl() ,true);
                return;
            }

            TracksObjectDataSource.SelectParameters.Add("playerID", TypeCode.Int32, thePlayer.PlayerId.ToInvariantString());

            if (thePlayer.PlayerType == MediaType.Audio)
            {
                MediaFileBrowser.BrowserType = "audio";
            }

            if (thePlayer.PlayerType == MediaType.Video)
            {
                MediaFileBrowser.BrowserType = "video";
            }
        }
        public void InstallContent(Module module, string configInfo)
        {
            if (string.IsNullOrEmpty(configInfo)) { return; }

            SiteSettings siteSettings = new SiteSettings(module.SiteId);
            SiteUser admin = SiteUser.GetNewestUser(siteSettings);

            XmlDocument xml = new XmlDocument();

            using (StreamReader stream = File.OpenText(HostingEnvironment.MapPath(configInfo)))
            {
                xml.LoadXml(stream.ReadToEnd());
            }

            MediaPlayer player = new MediaPlayer();
            player.ModuleGuid = module.ModuleGuid;
            player.ModuleId = module.ModuleId;
            player.PlayerType = MediaType.Audio;

            if ((xml.DocumentElement.Attributes["type"] != null) && (xml.DocumentElement.Attributes["type"].Value.Length > 0))
            {
                player.PlayerType = (MediaType)Enum.Parse(typeof(MediaType), xml.DocumentElement.Attributes["type"].Value);
            }

            MediaPlayer.Add(player);

            XmlNode tracksNode = null;
            foreach (XmlNode n in xml.DocumentElement.ChildNodes)
            {
                if (n.Name == "tracks")
                {
                    tracksNode = n;
                    break;
                }
            }

            if (tracksNode == null) { return; }

            foreach (XmlNode node in xml.DocumentElement.ChildNodes)
            {
                if (node.Name == "moduleSetting")
                {
                    XmlAttributeCollection settingAttributes = node.Attributes;

                    if ((settingAttributes["settingKey"] != null) && (settingAttributes["settingKey"].Value.Length > 0))
                    {
                        string key = settingAttributes["settingKey"].Value;
                        string val = string.Empty;
                        if (settingAttributes["settingValue"] != null)
                        {
                            val = settingAttributes["settingValue"].Value;
                            if ((key == "HeaderContent") || (key == "FooterContent"))
                            {
                                val = System.Web.HttpUtility.HtmlDecode(val);
                            }
                        }

                        ModuleSettings.UpdateModuleSetting(module.ModuleGuid, module.ModuleId, key, val);
                    }
                }
            }

            foreach (XmlNode trackNode in tracksNode.ChildNodes)
            {
                if (trackNode.Name == "track")
                {
                    XmlAttributeCollection trackAttrributes = trackNode.Attributes;

                    MediaTrack track = new MediaTrack();
                    track.PlayerId = player.PlayerId;
                    track.TrackType = player.PlayerType;

                    if ((trackAttrributes["name"] != null) && (trackAttrributes["name"].Value.Length > 0))
                    {
                        track.Name = trackAttrributes["name"].Value;
                    }

                    if ((trackAttrributes["artist"] != null) && (trackAttrributes["artist"].Value.Length > 0))
                    {
                        track.Artist = trackAttrributes["artist"].Value;
                    }

                    MediaTrack.Add(track);

                    XmlNode filesNode = null;
                    foreach (XmlNode n in trackNode.ChildNodes)
                    {
                        if (n.Name == "files")
                        {
                            filesNode = n;
                            break;
                        }
                    }

                    if (filesNode == null) { return; }

                    foreach (XmlNode fileNode in filesNode.ChildNodes)
                    {
                        if (fileNode.Name == "file")
                        {
                            MediaFile mediaFile = new MediaFile();
                            mediaFile.TrackId = track.TrackId;

                            XmlAttributeCollection fileAttrributes = fileNode.Attributes;

                            string targetFormat = string.Empty;
                            string sourcePath = string.Empty;

                            if ((fileAttrributes["targetPathFormat"] != null) && (fileAttrributes["targetPathFormat"].Value.Length > 0))
                            {
                                targetFormat = fileAttrributes["targetPathFormat"].Value;
                            }

                            if ((fileAttrributes["sourcePath"] != null) && (fileAttrributes["sourcePath"].Value.Length > 0))
                            {
                                sourcePath = HostingEnvironment.MapPath(fileAttrributes["sourcePath"].Value);
                            }

                            if (targetFormat != string.Empty)
                            {
                                mediaFile.FilePath = string.Format(CultureInfo.InvariantCulture, targetFormat, module.SiteId.ToInvariantString());

                                string directory = Path.GetDirectoryName(HostingEnvironment.MapPath(mediaFile.FilePath));
                                if (!Directory.Exists(directory))
                                {
                                    Directory.CreateDirectory(directory);
                                }

                                File.Copy(sourcePath, HostingEnvironment.MapPath(mediaFile.FilePath));

                                MediaFile.Add(mediaFile);
                            }
                            else //targetPathFormat is not defined so we don't need to move the file
                            {
                                mediaFile.FilePath = fileAttrributes["sourcePath"].Value;
                                MediaFile.Add(mediaFile);
                            }

                        }
                    }
                }
            }
        }