Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace libspotifysharpdemo
- {
- class MainClass
- {
- private static AutoResetEvent playbackDone = new AutoResetEvent(false);
- private static AutoResetEvent loggedOut = new AutoResetEvent(false);
- private static Track currentTrack = null;
- private static Player player = null;
- 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.Empty;
- string password = string.Empty;
- Console.WriteLine("Username");
- username = Console.ReadLine();
- Console.WriteLine("Password");
- password = Console.ReadLine();
- if(args.Length == 2)
- {
- username = args[0];
- password = args[1];
- }
- AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
- string tmpPath = "c:\\temp\\libspotify";
- try
- {
- if (!Directory.Exists(tmpPath))
- Directory.CreateDirectory(tmpPath);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.ToString());
- }
- int Status = (int)sp_error.BAD_USERNAME_OR_PASSWORD;
- 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