예제 #1
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);
        }
예제 #2
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);
        }