Пример #1
0
		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...");
		}
Пример #2
0
		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) {

			}
		}