Exemplo n.º 1
0
        public void UpdatePlayer()
        {
            TrackProgress.Invoke(t => t.Maximum = player.MaxTick);
            TrackProgress.Invoke(t => t.Value   = 0);
            if (player.CurrentTick < player.MaxTick)
            {
                TrackProgress.Invoke(t => t.Value = player.CurrentTick);
            }

            Bitmap playPauseBmp = (player.IsPlaying ? Properties.Resources.Pause : Properties.Resources.Play);

            TrackPlay.Invoke(t => t.Image = playPauseBmp);
        }
Exemplo n.º 2
0
        public async Task AddTrackAsync(SocketUser discordUser, string url)
        {
            var user = await _unitOfWork.UserRepository.GetUserByDiscordIdAsync(discordUser.Id);

            if (user == null)
            {
                user = CreateAppUser(discordUser);
                _unitOfWork.UserRepository.AddUser(user);
            }
            else
            {
                user.UpdateAppUser(discordUser);
            }

            if (_unitOfWork.HasChanges())
            {
                if (!await _unitOfWork.Complete())
                {
                    throw new DataContextException("Something went wrong saving the user.");
                }
            }

            if (!url.Contains("youtu.be") && !url.Contains("youtube.com"))
            {
                throw new InvalidUrlException("The link provided is invalid");
            }

            var youtubeId = GetYouTubeId(url);

            if (youtubeId == null)
            {
                throw new InvalidUrlException("Something is wrong with the URL provided");
            }

            var track = await _unitOfWork.TrackRepository.GetTrackByYoutubeIdAsync(youtubeId);

            if (track == null)
            {
                track = new Track {
                    YoutubeId  = youtubeId,
                    CreatedOn  = DateTime.UtcNow,
                    TrackPlays = new List <TrackPlay>()
                };

                try {
                    track = await _videoService.GetVideoDetails(track);
                } catch (Exception e) {
                    Console.WriteLine(e);
                }

                _unitOfWork.TrackRepository.AddTrack(track);

                if (!await _unitOfWork.Complete())
                {
                    throw new DataContextException("Something went wrong saving the Track.");
                }
            }

            var trackPlay = track.TrackPlays.FirstOrDefault(x => x.AppUserId == user.Id);

            if (trackPlay == null)
            {
                trackPlay = new TrackPlay {
                    AppUserId        = user.Id,
                    User             = user,
                    TrackId          = track.Id,
                    Track            = track,
                    TrackPlayHistory = new List <TrackPlayHistory>()
                };
                track.TrackPlays.Add(trackPlay);
            }

            trackPlay.TrackPlayHistory.Add(new TrackPlayHistory {
                CreatedOn = DateTime.UtcNow,
                TrackPlay = trackPlay
            });

            if (!await _unitOfWork.Complete())
            {
                throw new DataContextException("Something went wrong saving the AppUserTrack.");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a list of tracks determined from the GetNextTrack method. The minimum length of the playlist is specified and the playlist and the resulting trackplays are returned.
        /// </summary>
        /// <param name="trackList">The tracks to compose the list of</param>
        /// <param name="plays">The plays of the tracks</param>
        /// <param name="minMillisDuration">The minimum duration of the playlist in milliseconds</param>
        /// <param name="playsForPlaylist">The resulting trackPlays from playing the playlist</param>
        /// <returns>The playlist</returns>
        public List<Track> GetNextPlayList(List<Track> trackList, List<TrackPlay> plays, int minMillisDuration, out List<TrackPlay> playsForPlaylist)
        {
            int timeOfPlaylist = 0;
            List<Track> playlist = new List<Track>();
            playsForPlaylist = new List<TrackPlay>();

            for (int i = 0; i < minMillisDuration; )
            {
                Track nextTrack = GetNextTrack(trackList, plays);
                if (nextTrack.Length <= 0) throw new ArgumentException("Track has length equal to or below zero.");
                TrackPlay play = new TrackPlay(nextTrack.Id, DateTime.Now.AddMilliseconds(timeOfPlaylist));
                timeOfPlaylist = timeOfPlaylist + nextTrack.Length;
                playlist.Add(nextTrack);
                plays.Add(play);
                playsForPlaylist.Add(play);
                i = i + nextTrack.Length;
            }
            return playlist;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Whether the collection of trackplays contain an older trackplays than the target trackplay.
 /// </summary>
 /// <param name="targetTrack">The target trackplay to be compare against</param>
 /// <param name="plays">The collection of trackplays to investigate</param>
 /// <returns>Whether there is an older trackplay in the collection</returns>
 private Boolean ContainsOlderTrackPlay(TrackPlay targetTrack, List<TrackPlay> plays)
 {
     foreach (TrackPlay tp in plays)
     {
         if (tp.TimePlayed < targetTrack.TimePlayed) { return true; }
     }
     return false;
 }