Guest User

Untitled

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