示例#1
0
 public void SyncLiveWhenPlaying(string groupName, CurrentPlayingViewModel track, float duration)
 {
     var removeKeys = new List<string>();
     foreach (var key in lastJoiners.Where(p => p.Value == groupName).Select(p => p.Key))
     {
         Clients.Client(key).playLive(track, (int)duration);
         removeKeys.Add(key);
     }
     foreach (var removeKey in removeKeys)
     {
         lastJoiners.Remove(removeKey);
     }
 }
示例#2
0
        public void SyncLive(string groupName, CurrentPlayingViewModel track, float duration)
        {
            
            
            List<string> keys = new List<string>();
            foreach (var key in lastListener.Where(p=>p.Value == groupName).Select(p=>p.Key))
            {
                Clients.Client(key).playLive(track, (int) duration);
                keys.Add(key);
            }

            //Sending YouTube links after .playLive because it can take some time
            var youTube = YouTube.Default;
            var video = youTube.GetVideo("https://www.youtube.com/watch?v=" + track.TrackId);
            var youtubeLink = video.Uri;
            foreach (var key in keys)
            {
                Clients.Client(key).onPlaylinkGeneratedSync(youtubeLink, (int) duration);
                lastListener.Remove(key);
            }
        }
        public ActionResult GetNextTrack(long id)
        {
            var playlistTracks = playlistManager.ReadPlaylist(id).PlaylistTracks.OrderByDescending(p => p.Votes.Sum(v => v.Score))
                .Where(t => t.PlayedAt == null);

            if (!playlistTracks.Any()) return Json(null, JsonRequestBehavior.DenyGet);

            var track = playlistTracks.OrderByDescending(p=>p.Votes.Sum(v=>v.Score)).First(t => t.PlayedAt == null);
            var playingViewModel = new CurrentPlayingViewModel()
            {
                TrackId = track.Track.TrackSource.TrackId,
                Title = track.Track.Title,
                Artist = track.Track.Artist,
                NextTracks = playlistTracks.Where(p=>p.PlayedAt==null).ToList().Count(),
                CoverArtUrl = track.Track.CoverArtUrl
            };
             return Json(playingViewModel, JsonRequestBehavior.AllowGet);

        }
示例#4
0
 public void StartPlaying(CurrentPlayingViewModel track, string groupName)
 {
     if (playlistMasters.ContainsKey(groupName))
     {
         playlistMasters.Remove(groupName);
     }
     playlistMasters.Add(groupName, Context.ConnectionId);
     if (lastJoiners.ContainsKey(Context.ConnectionId))
     {
         lastJoiners.Remove(Context.ConnectionId);
     }
     Clients.OthersInGroup(groupName).playLive(track, 0);
     var youTube = YouTube.Default; // starting point for YouTube actions
     var video = youTube.GetVideo("https://www.youtube.com/watch?v=" + track.TrackId); // gets a Video object with info about the video
     Clients.OthersInGroup(groupName).onPlaylinkGenerated(video.Uri);
 }