Exemple #1
0
 public void Pause()
 {
     Current_Status = API.Pause;
 }
Exemple #2
0
 public void Play()
 {
     Current_Status = API.Resume;
 }
Exemple #3
0
 public Spotify()
 {
     cfid = API.CFID;
     Current_Status = API.Status;
 }
Exemple #4
0
        public Server()
        {
            // Default message.
            Console.WriteLine(
                "This is the CampFire listener, if you keep this running in the background with Spotify open it will play tracks when they are recieved by the webpage.\r\n");

            _api = new SpotifyAPI(SpotifyAPI.GetOAuth(), "SpotifyServer.spotilocal.com");
            _currentStatus = _api.Status;
            _cfid = _api.CFID;

            FleckLog.Level = LogLevel.Debug;

            var allSockets = new List<IWebSocketConnection>();
            var server = new WebSocketServer("ws://localhost:8181/CampFire");

            server.Start(socket =>
                {
                    socket.OnOpen = () =>
                        {
                            Console.WriteLine("Open connection.");
                            // Add the new connection to our list so we can send messages back.
                            allSockets.Add(socket);
                        };

                    socket.OnClose = () =>
                        {
                            Console.WriteLine("Closed connection, the CampFire webpage has been closed.");

                            // Make sure we remove them from out list when we are not connected to em.
                            allSockets.Remove(socket);
                        };

                    socket.OnMessage = message =>
                        {
                            // When a message is recieved it comes in the from NAME^spotify:track:oiasdoijasd so we split the string with ^ to get the name and uri.
                            string[] details = message.Split('^');

                            // Don't ask why we have to do this, if we don't it borks. heh.
                            string username = Convert.ToString(details[0]);
                            string uri = Convert.ToString(details[1]);

                            // Set our spotify to look at the new uri and then play it
                            _api.URI = uri;
                            _currentStatus = _api.Play;

                            string trackName = _currentStatus.track.track_resource.name;
                            string artistName = _currentStatus.track.artist_resource.name;

                            // Message all users that X user has played X, we have to do this because there is no other way of telling the other people connecting WHO played what song
                            allSockets.ToList().ForEach(s => s.Send(username + " played " + trackName + " - " + artistName));
                            Console.WriteLine("Playing: " + _currentStatus.track.track_resource.name + " - " +
                                                _currentStatus.track.artist_resource.name);
                        };
                });

            var inpt = Console.ReadLine();
            if (inpt != "exit")
            {
                Console.ReadLine();
            }
        }
        public static bool Init()
        {
            bool ret = false;

            try
            {
                _API = new SpotifyAPI(SpotifyAPI.GetOAuth(), "127.0.0.1");
                //It's required to get the contents of API.CFID before doing anything, even if you're not intending to do anything with the CFID
                _cfid = _API.CFID;

                if (_cfid.error != null)
                {
                    throw new Exception(string.Format("Spotify returned a error {0} (0x{1})", _cfid.error.message, _cfid.error.type));
                }

                _Current_Status = _API.Status;

                if (_cfid.error != null)
                {
                    throw new Exception(string.Format("Spotify returned a error {0} (0x{1})", _cfid.error.message, _cfid.error.type));
                }

                _tmr = new Timer()
                {
                    Interval = 5000, Enabled = true
                };
                _tmr.Elapsed += _tmr_Elapsed;
                _tmr.Start();

                ret = true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);

                ret = false;
            }

            return ret;
        }
 public static void CheckStatus()
 {
     _Current_Status = _API.Status;
 }
Exemple #7
0
        public void UpdateSpot()
        {
            if(initExcpt != null)
                return;

            try
            {
                currentStatus = api.Status;
            }
            catch (Exception e)
            {
                initExcpt = e;
            }
        }