Guest User

Untitled

a guest
Sep 21st, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. namespace libspotifysharpdemo
  2. {
  3.     class MainClass
  4.     {
  5.         private static AutoResetEvent playbackDone = new AutoResetEvent(false);
  6.         private static AutoResetEvent loggedOut = new AutoResetEvent(false);
  7.         private static Track currentTrack = null;
  8.         private static Player player = null;
  9.        
  10.         public static void Main(string[] args)
  11.         {
  12.             // If running in MonoDevelop / Visual Studio, set these in code directly
  13.             // and start w.o. parameters.
  14.             string username = string.Empty;
  15.             string password = string.Empty;
  16.  
  17.             Console.WriteLine("Username");
  18.             username = Console.ReadLine();
  19.             Console.WriteLine("Password");
  20.             password = Console.ReadLine();
  21.  
  22.  
  23.             if(args.Length == 2)
  24.             {
  25.                 username = args[0];
  26.                 password = args[1];
  27.             }
  28.            
  29.            
  30.             AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
  31.  
  32.             string tmpPath = "c:\\temp\\libspotify";
  33.  
  34.          
  35.  
  36.             try
  37.             {
  38.                 if (!Directory.Exists(tmpPath))
  39.                     Directory.CreateDirectory(tmpPath);
  40.             }
  41.             catch (Exception ex)
  42.             {
  43.                 Console.WriteLine(ex.ToString());
  44.             }
  45.             int Status = (int)sp_error.BAD_USERNAME_OR_PASSWORD;
  46.             Session s = Session.CreateInstance(key, tmpPath, tmpPath, "libspotify-sharp-test");
  47.            
  48.            
  49.             s.OnConnectionError += HandleOnConnectionError;
  50.             s.OnLoggedOut += HandleOnLoggedOut;
  51.             s.OnLoginComplete += HandleOnLoginComplete;
  52.             s.OnLogMessage += HandleOnLogMessage;
  53.             s.OnMessageToUser += HandleOnMessageToUser;        
  54.             s.OnPlayTokenLost += HandleOnPlayTokenLost;        
  55.             s.OnSearchComplete += HandleOnSearchComplete;          
  56.             s.OnMusicDelivery += HandleOnMusicDelivery;
  57.             s.OnEndOfTrack += HandleOnEndOfTrack;
  58.             s.OnImageLoaded += HandleOnImageLoaded;
  59.             s.OnPlaylistContainerLoaded += HandleOnPlaylistContainerLoaded;
  60.            
  61.  
  62.             Console.WriteLine("Logging in...");
  63.             s.LogIn(username, password);
  64.      
  65.            
  66.             // We want quality
  67.             s.PreferredBitrate(sp_bitrate.BITRATE_320k);
  68.            
  69.             playbackDone.WaitOne();
  70.             Console.WriteLine("Logging out..");
  71.             s.LogOut();
  72.             loggedOut.WaitOne(5000, false);
  73.             Console.WriteLine("Logged out");
  74.  
  75.             if (!IsWindows())
  76.             {
  77.                 // FIXME
  78.                 // This is really ugly. However, mono doesn't exit even if all our threads are
  79.                 // terminated. libspotify internal threads are are still active and prevents mono
  80.                 // from exiting. Should be done with some other signal than SIGKILL.
  81.                 System.Diagnostics.Process.GetCurrentProcess().Kill();
  82.             }
  83.         }
Add Comment
Please, Sign In to add comment