static async Task PlayQueueTest() { Console.WriteLine("Enter username and password (a line for each)"); Session session = await Spotify.CreateSession(key, cache, settings, userAgent); session.MusicDelivered += session_MusicDeliver; Error err; do { err = await session.Login(Console.ReadLine(), Console.ReadLine(), false); if (err != Error.OK) { Console.WriteLine("An error occurred while logging in.\n{0}", err.Message()); } } while (err != Error.OK); session.PreferredBitrate = BitRate.Bitrate320k; await session.PlaylistContainer; while (session.PlaylistContainer.Playlists.Count < 1) { Console.WriteLine("Found {0} playlists, retrying in 2 sec.", session.PlaylistContainer.Playlists.Count); await Task.Delay(TimeSpan.FromSeconds(2)); } AutoResetEvent are = new AutoResetEvent(false); PlayQueue queue = new PlayQueue(); session.EndOfTrack += (s, e) => { if (!queue.IsEmpty) { var track = queue.Dequeue(); session.PlayerUnload(); session.PlayerLoad(track); session.PlayerPlay(); } else { are.Set(); } }; var playlist = await session.PlaylistContainer.Playlists[0]; queue.Seed = playlist.Tracks; if (!queue.IsEmpty) { var track = await queue.Dequeue(); session.PlayerUnload(); session.PlayerLoad(track); session.PlayerPlay(); are.WaitOne(); } }
static async Task PlayQueueTest() { Console.WriteLine("Enter username and password (a line for each)"); Session session = await Spotify.CreateSession(key, cache, settings, userAgent); session.MusicDelivered += session_MusicDeliver; Error err; do { err = await session.Login(Console.ReadLine(), Console.ReadLine(), false); if (err != Error.OK) { Console.WriteLine("An error occurred while logging in.\n{0}", err.Message()); } } while (err != Error.OK); session.PreferredBitrate = BitRate.Bitrate320k; await session.PlaylistContainer; while (session.PlaylistContainer.Playlists.Count < 1) { Console.WriteLine("Found {0} playlists, retrying in 2 sec.", session.PlaylistContainer.Playlists.Count); await Task.Delay(TimeSpan.FromSeconds(2)); } AutoResetEvent are = new AutoResetEvent(false); PlayQueue queue = new PlayQueue(); session.EndOfTrack += (s, e) => { if (!queue.IsEmpty) { var track = queue.Dequeue(); session.PlayerUnload(); session.PlayerLoad(track); session.PlayerPlay(); } else { are.Set(); } }; var playlist = await session.PlaylistContainer.Playlists[0]; queue.Seed = playlist.Tracks; if (!queue.IsEmpty) { var track = await queue.Dequeue(); session.PlayerUnload(); session.PlayerLoad(track); session.PlayerPlay(); are.WaitOne(); } }
public void Skip() { if (PlayQueue.Count == 0) { Stop(); //no more songs return; } Stop(); OnSongfinished(); CurrentSong = PlayQueue.Dequeue(); PlayedSongs.Enqueue(CurrentSong); Play(); }
static async Task Run() { Console.WriteLine("Enter username and password (a line for each)"); Session session = await Spotify.CreateSession(key, cache, settings, userAgent); session.MusicDelivered += session_MusicDeliver; await session.Login(Console.ReadLine(), Console.ReadLine(), false); session.PreferredBitrate = BitRate.Bitrate320k; await session.PlaylistContainer; while (session.PlaylistContainer.Playlists.Count < 1) { Console.WriteLine("Found {0} playlists, retrying in 2 sec.", session.PlaylistContainer.Playlists.Count); await Task.Delay(TimeSpan.FromSeconds(2)); } var toplist = await session.CreateToplistBrowse(ToplistType.Tracks, ToplistRegion.Everywhere, null); var toptrack = await toplist.Tracks[0]; Console.WriteLine("Most popular track on spotify: " + toptrack.Name); await session.Play(toptrack); PlayQueue queue = new PlayQueue(); var playlist = await session.PlaylistContainer.Playlists[0]; queue.Seed = playlist.Tracks; while (!queue.IsEmpty) await session.Play(queue.Dequeue()); Console.WriteLine("Playing random from " + playlist.Name); var track = await playlist.Tracks[new Random().Next(playlist.Tracks.Count)]; Console.WriteLine("Found track " + track.Name); await track.Album; await track.Album.Browse(); // test await track.Artists[0].Browse(ArtistBrowseType.NoAlbums); // test var coverId = track.Album.CoverId; var image = await Image.FromId(session, coverId); var imageData = image.GetImage(); imageData.Save("cover.jpg"); await session.Play(track); playlist = await session.Starred; Console.WriteLine("Playing random starred track"); track = await playlist.Tracks[new Random().Next(playlist.Tracks.Count)]; Console.WriteLine("Found track " + track.Name); await session.Play(track); Console.WriteLine("Enter song search"); var search = await session.SearchTracks(Console.ReadLine(), 0, 1); if (search.Tracks.Count > 0) { track = await search.Tracks[0]; Console.WriteLine("Playing " + track.Name); await session.Play(track); } else { Console.WriteLine("No matching tracks."); } await session.Logout(); }
public void Play() { if (State == PlayState.Playing) { Stop(); } if (_playThread == null) { _playThread = new Thread(new ThreadStart(ProgressThread)); } if (State == PlayState.Paused) { Pause(); } else if (PlayQueue.Count > 0) { State = PlayState.Playing; if (CurrentSong == null) { CurrentSong = PlayQueue.Dequeue(); PlayedSongs.Enqueue(CurrentSong); } } else { //nothing to play Stop(); } if (State == PlayState.Playing) { if (CurrentSong == null) { CurrentSong = PlayQueue.Peek(); } if (!CurrentSong.IsPlayable || (!Config.Instance.PlayWavs && CurrentSong.FileType.ToLowerInvariant() == "wav")) { Console.ResetColor(); Console.ForegroundColor = ConsoleColor.DarkRed; Console.Out.WriteLine("cannot play song. skipping."); Console.ResetColor(); Skip(); return; } State = PlayState.Playing; ConsoleUtils.UOut(ConsoleColor.DarkGreen, "downloading..."); //todo : this should happen in a background thread. byte[] songBytes = Subsonic.PreloadSong(CurrentSong.Id); _hgcFile = GCHandle.Alloc(songBytes, GCHandleType.Pinned); ConsoleUtils.UOut(ConsoleColor.DarkGreen, "download complete."); _currentSongChannel = Bass.BASS_StreamCreateFile(_hgcFile.AddrOfPinnedObject(), 0, songBytes.Length, BASSFlag.BASS_SAMPLE_FLOAT); Bass.BASS_ChannelPlay(_currentSongChannel, false); if (!_playThread.IsAlive) { if (_playThread.ThreadState == ThreadState.Running) { _playThread.Join(); } _playThread = new Thread(new ThreadStart(ProgressThread)); _playThread.Start(); } } }
public void Paint(object sender, SKCanvas canvas) { // See if someone went sneaky and changed our dimensions canvas.GetDeviceClipBounds(out var bounds); Resize(bounds.Width, bounds.Height, GameBoard); // Update currently playing animation bool end_of_anim = false; if (Playing != null) { end_of_anim = Playing.Heartbeat(); } // Clear canvas first canvas.Clear(SKColors.White); // Scale font to size of screen var textPaint = new SKPaint { IsAntialias = true, Color = SKColors.Black, TextSize = Dimensions.CellHeight }; // Draw strengths of each player DrawPlayerScores(canvas, textPaint); // Draw each zone foreach (var z in GameBoard.Zones) { bool isAttacking = (z == Attacking || z == Defending); // Figure out color to use SKColor color = GetBaseColor(z); if (Playing != null) { color = Playing.RecolorZone(z); } if (isAttacking) { color = Lighten(color, 0.7f); } // Figure out rectangle SKRect r = Dimensions.ZoneToRect[z]; // Draw rectangle SKPaint p = new SKPaint() { Color = color, Style = SKPaintStyle.Fill, }; canvas.DrawRect(r, p); // Draw border if attacking if (isAttacking) { SKPaint border = new SKPaint() { Color = SKColors.Black, Style = SKPaintStyle.Stroke, }; canvas.DrawRect(r, border); } // Draw strength centered in the box DrawPips(canvas, r, color, z.Strength); } // Do we need to draw the "End Turn" button? if (GameBoard.CurrentPlayer.IsHuman) { canvas.DrawRoundRect(Dimensions.EndTurnRect, new SKPaint() { Style = SKPaintStyle.Fill, Color = SKColors.DarkGray }); canvas.DrawRoundRect(Dimensions.EndTurnRect, new SKPaint() { Style = SKPaintStyle.Stroke, Color = SKColors.LightGray }); DrawCenteredText(canvas, "END TURN", Dimensions.EndTurnRect.Rect, textPaint); } // Are we ready for the next animation? if (end_of_anim || Playing == null) { if (PlayQueue.Count > 0) { Playing = PlayQueue.Dequeue(); } else { // If the current player is a bot, do another attack if (!GameBoard.CurrentPlayer.IsHuman) { TakeBotAction(); } else { Playing = null; } } } }