Example #1
0
 protected override void OnAppearing()
 {
     App.Router.Subscribe<HubMessagePlaylistWasUpdated> ().OnSuccess ((ep, m) => {
         tracks.Clear ();
         foreach (var t in m.Playlist) {
             tracks.Add (t);
         }
         currentTrack = m.PlayingTrack;
         SetCurrentTrack ();
     });
     base.OnAppearing ();
 }
Example #2
0
 private int comparePlaylistEntries(PlaylistEntry e1, PlaylistEntry e2)
 {
     return e1.Priority == e2.Priority ? e2.Id - e1.Id:
         e2.Priority < e1.Priority ? -1: 1;
 }
Example #3
0
        public PlaylistEntry QueueTrack(User user, Track track)
        {
            UpdateUserPriorities ();

            if (!_usersActivities.ContainsKey (user.Id)) {
                var newActivity = new UserActivitiesRecord () {
                    basePriority = 1.0,
                    activitiesCount = 0,
                    lastActivityTime = DateTime.Now
                };
                _usersActivities.Add (user.Id, newActivity);
            }
            var activitiesRecord = _usersActivities [user.Id];

            if (activitiesRecord.activitiesCount++ == 0)
                ++_activeUsersCount;

            var entry = new PlaylistEntry () {
                User = user,
                Track = track,
                Id = _freeEntryId++,
                LikesNum = 0,
                DislikesNum = 0,
                Priority = activitiesRecord.basePriority
            };
            activitiesRecord.basePriority *= Math.Pow (0.5, track.Duration.TotalMilliseconds / AVG_TRACK_LENGTH_MS);
            _usersMarkedByEntryId.Add (entry.Id, new List<string> ());
            _usersMarkedByEntryId [entry.Id].Add (user.Id);

            Playlist.Add (entry);
            Playlist.Sort (comparePlaylistEntries);

            _playlistEntries.Add (entry);

            if (!_playing)
                Play ();

            return entry;
        }