Exemplo n.º 1
0
        void nowPlaying(Song song, string trackId)
        {
            var track          = Database.Main.GetObject <Track, TempTrack>(trackId);
            var noPlayingTrack = new NowplayingTrack(song.Artist, song.Name,
                                                     TimeSpan.FromSeconds((int)(track?.Duration ?? 0)));

            try
            {
                lock (locker)
                {
                    manager.ReportNowplaying(noPlayingTrack);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    session.Authenticate(session.UserName, session.Password);
                    lock (locker)
                    {
                        manager.ReportNowplaying(noPlayingTrack);
                    }
                }
                catch (Exception e)
                {
                    LogManager.Shared.Report(e);
                }
            }
        }
Exemplo n.º 2
0
        public void NowPlaying(YouTubeEntry song)
        {
            if (!IsLoged)
            {
                return;
            }
            try
            {
                string Artist = string.Empty;
                string Title  = string.Empty;
                int    length = 0;
                string _title = song.Title.Text;
                if (_title.Contains("-"))
                {
                    Artist = _title.Split('-')[0].Trim();
                    Title  = _title.Split('-')[1].Trim();
                }
                if (song.Duration != null && song.Duration.Seconds != null)
                {
                    length = Convert.ToInt32(song.Duration.Seconds, 10);
                }

                if (!string.IsNullOrEmpty(Artist) && !string.IsNullOrEmpty(Title) && length > 0)
                {
                    NowplayingTrack track1 = new NowplayingTrack(Artist, Title, new TimeSpan(0, 0, length));
                    manager.ReportNowplaying(track1);
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
        /// <summary>
        /// UpdateNowPlaying
        /// </summary>
        public void UpdateNowPlaying(PropertyData data, bool isAuthRetry = false)
        {
            try
            {
                if (!this.session.Authenticated)
                {
                    return;
                }

                var entry = new NowplayingTrack(data.Artist, data.Title, data.GetDurationSpan());
                entry.Album = data.Album;
                connection.ReportNowplaying(entry);
            }
            catch (AuthenticationFailureException)
            {
                if (isAuthRetry)
                {
                    return;
                }
                Authenticate();
                UpdateNowPlaying(data, true);
            }
        }