public static CatalogController CreateCatalogController (Catalog catalog, PlayQueue<StreamingPlayer> playQueue) { var vc = (CatalogController) MainStoryboard.InstantiateViewController ("CatalogController"); vc.Catalog = catalog; vc.PlayQueue = playQueue; return vc; }
public PlayQueue GetPlayQueue() { RestCommand command = new RestCommand(); command.MethodName = "getPlayQueue"; return(PlayQueue.Create(Client.GetResponseXDocument(command).RealRoot())); }
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 async override void ViewDidLoad () { base.ViewDidLoad (); this.CatalogBrowser.TracksQueued += async (sender, tracks) => { try { await playQueue.PlayAsync (tracks); } catch (OperationCanceledException) { // This is ok, let's ignore it! } catch (Exception ex) { LoggingService.LogError (ex, "An unhandled exception happened playing a song"); } }; var serverDetails = Caches.LoadKnownServers ().FirstOrDefault (t => t.Default); var server = new TunezServer (serverDetails); var catalog = await server.FetchCatalog (Path.Combine (CacheDirectory, "tunez.catalog"), System.Threading.CancellationToken.None); var playPauseItem = (NSToolbarItem) NSApplication.SharedApplication.Windows[0].Toolbar.Items[0]; var playPauseButton = (NSButton) NSApplication.SharedApplication.Windows[0].Toolbar.Items[0].View; var progress = NSApplication.SharedApplication.Windows[0].Toolbar.Items[1]; var label = (NSTextField)NSApplication.SharedApplication.Windows[0].Toolbar.Items[2].View; var monitors = new TrackMonitorGroup { new PlayingProgressMonitor (progress, label), }; if (!string.IsNullOrEmpty (LastFMAppCredentials.APIKey)) monitors.Add (new ScrobblingMonitor (new Scrobbler (Caches.Scrobbler))); playQueue = new PlayQueue<MacStreamingPlayer> (server, new NullNetworkChangedListener (), monitors); PlayPauseButton (playPauseItem, playPauseButton); PopulateBrowser (catalog); LoggingService.LogInfo ("Initialization complete..."); }
public void TrackQueueHasSongs_No_ReturnsFalse() { //Arrange PlayQueue playQueue = new PlayQueue(); bool result; //Act result = playQueue.TrackQueueHasSongs(); //Assert Assert.AreEqual(result, false); //Check if the queue has tracks, when no tracks are added -> returns false }
public BufferingManager (PlayQueue<StreamingPlayer> playQueue, CancellationToken token) { playQueue.BufferingStarted += BufferingStarted; playQueue.BufferingCompleted += BufferingCompleted; Token = token; Token.Register (() => { playQueue.BufferingStarted -= BufferingStarted; playQueue.BufferingCompleted -= BufferingCompleted; BufferingCompleted (); }); }
void MusicService_PlaybackStarted(object sender, EventArgs e) { this.PlayHistory.Push(MusicService.NowPlayingTrack); List <Track> tracks = this.Apps[CurrentURI].spiderView.activeBoard.GetQueue(MusicService.NowPlayingTrack); PlayQueue.Clear(); foreach (Track track in tracks) { PlayQueue.Enqueue(track); } }
public void TrackQueueHasSongs_Yes_ReturnsTrue() { //Arrange PlayQueue playQueue = new PlayQueue(); bool result; //Act playQueue.TrackQueue.Enqueue(new Track()); //Enqueue track to the queue result = playQueue.TrackQueueHasSongs(); //Assert Assert.AreEqual(result, true); //Check if the track is added to the queue -> returns true }
private static async Task DumpQueuedSongs(PlayQueue queue) { Console.WriteLine($"\tSongs:"); await foreach (var page in queue.GetSongs(500)) { foreach (var song in page) { Console.WriteLine($"\t\t{song}"); } } Console.WriteLine($"Done."); }
public void Start() { libraryTracer.Trace("Starting"); LoadCollection(); libraryTracer.Trace("Collection loaded"); PlayQueue.Start(); libraryTracer.Trace("Play Queue Loaded"); }
public void Skip() { if (PlayQueue.Count == 0) { Stop(); //no more songs return; } Stop(); OnSongfinished(); CurrentSong = PlayQueue.Dequeue(); PlayedSongs.Enqueue(CurrentSong); Play(); }
} // album image property #endregion public MainWindowViewModel(Login loggedInUser) { User = loggedInUser; PlayQueue = PlayQueueController.PQ; AllPlaylistsController = new AllPlaylistsController(User.User.ConsumerID); InitializeCommands(); InitializeViewModels(); Navigation.InitializeViewModelNavigation(); Navigation.ViewModelChanged += ChangeViewModel; InitializeCurrentTrackElement(); TestTrackMethod(); PlaylistViewModel = new PlaylistViewModel(this, PlaylistController.Playlist); }
public void AddToQueue() { var dlg = new Microsoft.Win32.OpenFileDialog { Filter = "Audio Files (.mp3)|*.mp3;*.wav", Multiselect = true }; bool?result = dlg.ShowDialog(); if (result != true) { return; } var files = dlg.FileNames; foreach (var file in files) { PlayQueue.Add(new AudioFile(Path.GetFileName(file), file)); } }
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 Task UpdatePlayQueueAsync(PlayQueue playQueue, CancellationToken cancellationToken) { throw new NotImplementedException(); }
async void ConnectToServer (ServerDetails serverDetails) { connectingCancellation.Cancel (); connectingCancellation = new CancellationTokenSource (); try { var token = connectingCancellation.Token; Server = new TunezServer (serverDetails); var connectingViewController = StoryboardHelper.Main.CreateConnectingViewController (); connectingViewController.IsConnecting = true; connectingViewController.LoadingMessage = string.Format ("Fetching catalog from {0}...", serverDetails.FullAddress); ContentViewController.Content = connectingViewController; var newCatalog = await Server.FetchCatalog (Caches.TunezCatalog, token); var playQueue = new PlayQueue<StreamingPlayer> (Server, new NetworkChangedListener (), Monitors); playQueue.Paused += () => NowPlayingStatusView.IsPaused = true; playQueue.Playing += () => NowPlayingStatusView.IsPaused = false; playQueue.BufferingStarted += () => NowPlayingStatusView.IsBuffering = true; playQueue.BufferingCompleted += () => NowPlayingStatusView.IsBuffering = false; BufferingManager = new BufferingManager (playQueue, token); Monitors.Initialize (null); if (CatalogController != null) CatalogController.PlayQueue.Dispose (); CatalogController = StoryboardHelper.Main.CreateCatalogController (newCatalog, playQueue); connectingViewController.IsConnecting = false; ContentViewController.Content = CatalogController; } catch (OperationCanceledException) { } }
private byte[] OnGetAccountInfo(GameSession session, byte[] body) { GetAccountInfo request = new GetAccountInfo(); using(Stream stream = new MemoryStream(body)) { request.Deserialize(stream); } Debug.WriteLine("LOG " + request.Request_); if(request.Request_ == GetAccountInfo.Request.CAMPAIGN_INFO) { ProfileProgress response = new ProfileProgress() { Progress = 6, BestForge = 0 }; return response.EncodeResponse(233); } if(request.Request_ == GetAccountInfo.Request.BOOSTERS) { BoosterList response = new BoosterList(); response.List.Add(new BoosterInfo() { Type = (int)BoosterType.Classic, Count = 10 }); response.List.Add(new BoosterInfo() { Type = (int)BoosterType.GvG, Count = 10 }); response.List.Add(new BoosterInfo() { Type = (int)BoosterType.TGT, Count = 10 }); return response.EncodeResponse(224); } if(request.Request_ == GetAccountInfo.Request.FEATURES) { GuardianVars response = new GuardianVars() { ShowUserUI = 1 }; return response.EncodeResponse(264); } if(request.Request_ == GetAccountInfo.Request.MEDAL_INFO) { MedalInfo response = new MedalInfo() { SeasonWins = 0, Stars = 0, Streak = 0, StarLevel = 1, LevelStart = 1, LevelEnd = 3, CanLose = false }; return response.EncodeResponse(232); } if(request.Request_ == GetAccountInfo.Request.NOTICES) { ProfileNotices response = new ProfileNotices(); return response.EncodeResponse(212); } if(request.Request_ == GetAccountInfo.Request.DECK_LIST) { DeckList response = new DeckList(); foreach(Deck deck in session.Server.Database.Table<Deck>().Where(d => d.DeckType == DeckType.PRECON_DECK)) { response.Decks.Add(deck.ToDeckInfo()); } foreach(Deck deck in session.Server.Database.Table<Deck>().Where(d => d.DeckType == DeckType.NORMAL_DECK && d.AccountID == session.Account.ID)) { response.Decks.Add(deck.ToDeckInfo()); } return response.EncodeResponse(202); } if(request.Request_ == GetAccountInfo.Request.COLLECTION) { Collection response = new Collection(); foreach(DbfCard card in session.Server.Database.Table<DbfCard>().Where(c => c.Collectible)) { response.Stacks.Add(new CardStack() { LatestInsertDate = DateTime.Now.ToPegasusDate(), NumSeen = 2, Count = 2, CardDef = new PegasusShared.CardDef() { Asset = card.ID, Premium = 0 } }); } return response.EncodeResponse(207); } if(request.Request_ == GetAccountInfo.Request.DECK_LIMIT) { ProfileDeckLimit response = new ProfileDeckLimit() { DeckLimit = 9 }; return response.EncodeResponse(231); } if(request.Request_ == GetAccountInfo.Request.CARD_VALUES) { CardValues response = new CardValues() { CardNerfIndex = 0 }; return response.EncodeResponse(260); } if(request.Request_ == GetAccountInfo.Request.ARCANE_DUST_BALANCE) { ArcaneDustBalance response = new ArcaneDustBalance() { Balance = 10000 }; return response.EncodeResponse(262); } if(request.Request_ == GetAccountInfo.Request.NOT_SO_MASSIVE_LOGIN) { NotSoMassiveLoginReply response = new NotSoMassiveLoginReply(); return response.EncodeResponse(300); } if(request.Request_ == GetAccountInfo.Request.REWARD_PROGRESS) { RewardProgress response = new RewardProgress() { SeasonEnd = new DateTime(DateTime.UtcNow.AddMonths(1).Year, DateTime.UtcNow.AddMonths(1).Month, 1, 7, 0, 0).ToPegasusDate(), WinsPerGold = 3, GoldPerReward = 10, MaxGoldPerDay = 100, SeasonNumber = 1, XpSoloLimit = 60, MaxHeroLevel = 60, NextQuestCancel = DateTime.UtcNow.ToPegasusDate(), EventTimingMod = 0.291667f }; return response.EncodeResponse(271); } if(request.Request_ == GetAccountInfo.Request.GOLD_BALANCE) { GoldBalance response = new GoldBalance() { Cap = 999999, CapWarning = 2000, CappedBalance = 9999, BonusBalance = 0 }; return response.EncodeResponse(278); } if(request.Request_ == GetAccountInfo.Request.HERO_XP) { HeroXP response = new HeroXP(); for(int i = 2; i < 11; i++) { response.XpInfos.Add(new HeroXPInfo() { ClassId = i, Level = 30, CurrXp = 420, MaxXp = 840 }); } return response.EncodeResponse(283); } if(request.Request_ == GetAccountInfo.Request.PLAYER_RECORD) { PlayerRecords response = new PlayerRecords(); return response.EncodeResponse(270); } if(request.Request_ == GetAccountInfo.Request.CARD_BACKS) { CardBacks response = new CardBacks() { DefaultCardBack = 0 }; foreach(DbfCardBack cardBack in session.Server.Database.Table<DbfCardBack>()) { response.CardBacks_.Add(cardBack.ID); } return response.EncodeResponse(236); } if(request.Request_ == GetAccountInfo.Request.FAVORITE_HEROES) { FavoriteHeroesResponse response = new FavoriteHeroesResponse(); foreach(FavoriteHero hero in session.Server.Database.Table<FavoriteHero>().Where(h => h.AccountID == session.Account.ID)) { response.FavoriteHeroes.Add(new PegasusShared.FavoriteHero() { ClassId = hero.ClassID, Hero = new PegasusShared.CardDef() { Asset = hero.CardID, Premium = hero.Premium, } }); } return response.EncodeResponse(318); } if(request.Request_ == GetAccountInfo.Request.ACCOUNT_LICENSES) { AccountLicensesInfoResponse response = new AccountLicensesInfoResponse(); return response.EncodeResponse(325); } if(request.Request_ == GetAccountInfo.Request.BOOSTER_TALLY) { BoosterTallyList response = new BoosterTallyList(); return response.EncodeResponse(313); } if(request.Request_ == GetAccountInfo.Request.MEDAL_HISTORY) { MedalHistory response = new MedalHistory(); response.Medals.Add(new MedalHistoryInfo() { LegendRank = 1, LevelEnd = 0, LevelStart = 0, Season = 1, StarLevel = 0, Stars = 0, When = new DateTime(DateTime.UtcNow.AddMonths(-1).Year, DateTime.UtcNow.AddMonths(-1).Month, 1, 7, 0, 0).ToPegasusDate() }); return response.EncodeResponse(234); } if(request.Request_ == GetAccountInfo.Request.PVP_QUEUE) { PlayQueue response = new PlayQueue() { Queue = new PlayQueueInfo() { GameType = BnetGameType.BGT_NORMAL } }; return response.EncodeResponse(286); } Debug.WriteLine("ERR AccountHandler.OnGetAccountInfo missing " + request.Request_); return null; }
//private DispatcherTimer _dtimer = null; private async void ThrottledPlaybackStateChanged(MediaPlayer player) { if (_playbackStateChangePending) { // A change has already been noted, and the 'state changed' handler will get called anyway some time within the next 100ms return; } else { _playbackStateChangePending = true; await Task.Delay(100); // allow 100ms for subsequent state changes to come in _playbackStateChangePending = false; // // Now adjust the appearance of the Pause/Play button as needed, and kick off playback of the next track in the queue, if there is one. // if (player.PlaybackSession == null) // error - never started { } else if (player.PlaybackSession.PlaybackState == MediaPlaybackState.Paused) { bool trackFinished = false; //at the end of a track? if (player.PlaybackSession.Position != TimeSpan.Zero && player.PlaybackSession.Position.Add(TimeSpan.FromSeconds(1)) >= player.PlaybackSession.NaturalDuration) { // Position is not at the start of the media, and is equal/near to the duration of the player's media, // This means we are at the end of a track trackFinished = true; } MainPage.SetPlayButtonAppearance(false); // Set the Play button to display a "play" label, and do 'play' when tapped. if (trackFinished) // paused, and at the end of a track { MainPage.SetNowPlaying(""); // "***FINISHED: " + player.PlaybackSession.PlaybackState.ToString() + " " + player.PlaybackSession.Position.TotalSeconds.ToString() + "/" + player.PlaybackSession.NaturalDuration.TotalSeconds.ToString()); // set the text label at the bottom of the slider to blank. if (PlayQueue.Count > 0) // (this is just defensive coding, it should always be true) { PlayQueue.RemoveAt(0); // We've finished this track, so remove it from the top of the play queue. } if (PlayQueue.Count > 0) // if there is now a track at the top of the queue ... { ToccataModel.Play(this.PlayQueue[0].storage); // ... start playing it. } else { ToccataModel.Stop(); // ... otherwise, we should hard-stop the player, leaving it ready to play something, when something is queued up. } } else // paused but not finished the track - e.g. because the user tapped the Pause button. { // MainPage.SetNowPlaying("***PAUSED: " + player.PlaybackSession.PlaybackState.ToString()+" "+ player.PlaybackSession.Position.TotalSeconds.ToString()+"/"+ player.PlaybackSession.NaturalDuration.TotalSeconds.ToString()); } } else // playing, buffering, opening, none, or whatever { if (player.PlaybackSession.PlaybackState == MediaPlaybackState.Playing) { MainPage.SetPlayButtonAppearance(true); // Set the Play button to display a "pause" label, and do 'pause' when tapped. } else // could be 'buffering', 'opening' or 'none' - anyhow, it's a state in which the media is not (yet) playing. { MainPage.SetPlayButtonAppearance(false); // Set the Play button to display a "play" label, and do 'play' when tapped. } if (PlayQueue.Count > 0) // (this is just defensive coding, it should always be true) { MainPage.SetNowPlaying(PlayQueue[0].DisplayName + " (" + PlayQueue[0].storage.Path + ")"); } } } }
public void PreInitalize() { PlayQueue.Initalize(); }
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; } } } }
private void Handle_contentsViewModelPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "SelectedSong" && !ignoreChanges && ServiceManager.PlayerEngine.CurrentState != PlayerState.Playing) { var sngs = _contents.ViewModel.Songs.ToList(); var skip = sngs.IndexOf(_contents.ViewModel.SelectedSong); _queue = new PlayQueue(sngs.Skip(skip), sngs.Take(skip)); //Console.WriteLine (_queue.Current.DisplayName); if (ServiceManager.PlaybackController.ShuffleMode != "off") { _queue.Shuffle(null); } //Console.WriteLine (_queue.Current.DisplayName); ServiceManager.PlayerEngine.OpenPlay(_queue.Current); } }
public List <Song> GetQueue() { return(PlayQueue.ToList()); }
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(); } } }