Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void Main(string[] args)
- {
- // If running in MonoDevelop / Visual Studio, set these in code directly
- // and start w.o. parameters.
- string username;
- string password;
- Console.WriteLine("Username");
- username = Console.ReadLine();
- Console.WriteLine("Password:");
- password = Console.ReadLine();
- if(args.Length == 2)
- {
- username = args[0];
- password = args[1];
- }
- if(string.IsNullOrEmpty(password) || string.IsNullOrEmpty(username))
- {
- Console.WriteLine("Check Username and Password");
- return;
- }
- AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
- string tmpPath = string.Empty;
- if (IsWindows())
- {
- tmpPath = "c:\\temp\\libspotify";
- }
- else
- tmpPath = "/tmp/libspotify";
- try
- {
- if (!Directory.Exists(tmpPath))
- Directory.CreateDirectory(tmpPath);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.ToString());
- }
- Session s = Session.CreateInstance(key, tmpPath, tmpPath, "libspotify-sharp-test");
- s.OnConnectionError += HandleOnConnectionError;
- s.OnLoggedOut += HandleOnLoggedOut;
- s.OnLoginComplete += HandleOnLoginComplete;
- s.OnLogMessage += HandleOnLogMessage;
- s.OnMessageToUser += HandleOnMessageToUser;
- s.OnPlayTokenLost += HandleOnPlayTokenLost;
- s.OnSearchComplete += HandleOnSearchComplete;
- s.OnMusicDelivery += HandleOnMusicDelivery;
- s.OnEndOfTrack += HandleOnEndOfTrack;
- s.OnImageLoaded += HandleOnImageLoaded;
- s.OnPlaylistContainerLoaded += HandleOnPlaylistContainerLoaded;
- Console.WriteLine("Logging in...");
- s.LogIn(username, password);
- // We want quality
- s.PreferredBitrate(sp_bitrate.BITRATE_320k);
- playbackDone.WaitOne();
- Console.WriteLine("Logging out..");
- s.LogOut();
- loggedOut.WaitOne(5000, false);
- Console.WriteLine("Logged out");
- if (!IsWindows())
- {
- // FIXME
- // This is really ugly. However, mono doesn't exit even if all our threads are
- // terminated. libspotify internal threads are are still active and prevents mono
- // from exiting. Should be done with some other signal than SIGKILL.
- System.Diagnostics.Process.GetCurrentProcess().Kill();
- }
- }
Add Comment
Please, Sign In to add comment