public EditAudioView(Audio audio)
        {
            InitializeComponent();

            _viewModel = new EditAudioViewModel();
            this.DataContext = _viewModel;
            _viewModel.Track = audio;
        }
Esempio n. 2
0
        public static Audio ToAudio(this LastFmTrack audio)
        {
            var result = new Audio();
            result.Title = audio.Title;
            result.Artist = audio.Artist;
            result.Duration = TimeSpan.FromSeconds(audio.Duration);

            return result;
        }
        public TrackNotifcationView(Audio track)
        {
            _track = track;

            InitializeComponent();

            _timer = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromSeconds(7);
            _timer.Tick += _timer_Tick;
        }
Esempio n. 4
0
        public static Audio ToAudio(this VkAudio audio)
        {
            var result = new Audio();
            result.Id = audio.Id;
            result.Title = audio.Title;
            result.Artist = audio.Artist;
            result.AlbumId = audio.AlbumId;
            result.Duration = audio.Duration;
            result.LyricsId = audio.LyricsId;
            result.OwnerId = audio.OwnerId;
            result.Url = audio.Url;
            result.GenreId = audio.GenreId;
            result.IsAddedByCurrentUser = audio.OwnerId == ViewModelLocator.Vkontakte.AccessToken.UserId;

            return result;
        }
Esempio n. 5
0
        public static async Task<bool> Scrobble(Audio audio)
        {
            var time = (int)DateTimeConverter.ToUnixTime(DateTime.Now);

            await _lastFm.Track.Scrobble(audio.Artist, audio.Title, time.ToString(), null, (int)audio.Duration.TotalSeconds);
            return true;
        }
Esempio n. 6
0
 public static async Task<bool> UpdateNowPlaying(Audio audio)
 {
     await _lastFm.Track.UpdateNowPlaying(audio.Artist, audio.Title, null, (int)audio.Duration.TotalSeconds);
     return true;
 }
Esempio n. 7
0
        public static async Task<bool> RemoveAudio(Audio audio)
        {
            var result = await _vkontakte.Audio.Delete(audio.Id, audio.OwnerId);
            if (result)
            {
                audio.IsAddedByCurrentUser = false;
            }

            return result;
        }
Esempio n. 8
0
        public static async Task<bool> AddAudio(Audio audio, string captchaSid = null, string captchaKey = null)
        {
            if (string.IsNullOrEmpty(audio.Url))
            {
                var vkAudio = await GetAudioByArtistAndTitle(audio.Artist, audio.Title);
                if (vkAudio != null)
                {
                    audio.Id = vkAudio.Id;
                    audio.Artist = vkAudio.Artist;
                    audio.Title = vkAudio.Title;
                    audio.Url = vkAudio.Url;
                    audio.OwnerId = vkAudio.OwnerId;
                    audio.AlbumId = vkAudio.AlbumId;
                    audio.LyricsId = vkAudio.LyricsId;
                }
            }

            var newId = await _vkontakte.Audio.Add(audio.Id, audio.OwnerId, captchaSid: captchaSid, captchaKey: captchaKey);
            if (newId > 0)
            {
                audio.Id = newId;
                audio.OwnerId = _vkontakte.AccessToken.UserId;
                audio.IsAddedByCurrentUser = true;
                return true;
            }
            return false;
        }
Esempio n. 9
0
        public static async Task<bool> SetMusicStatus(Audio audio)
        {
            var result = await _vkontakte.Status.SetBroadcast(audio != null ? audio.OwnerId + "_" + audio.Id : null);

            return result;
        }
Esempio n. 10
0
        private static void PlaySong(EchoSong song)
        {
            var audio = new Audio()
            {
                Title = song.Title,
                Artist = song.ArtistName
            };

            _currentSong = song;

            AudioService.Play(audio);
            AudioService.Playlist.Insert(0, audio);
            //AudioService.SetCurrentPlaylist(new[] { audio }, true);
        }
Esempio n. 11
0
        private async Task LikeDislikeAudio(Audio audio, bool captchaNeeded = false, string captchaSid = null, string captchaImg = null)
        {
            if (audio == null)
                return;

            IsWorking = true;

            string captchaKey = null;
            if (captchaNeeded)
            {
                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new CaptchaRequestView(captchaSid, captchaImg);
                var result = await flyout.ShowAsync();
                if (string.IsNullOrEmpty((string)result))
                {
                    IsWorking = false;
                    return;
                }
                else
                {
                    captchaKey = (string)result;
                }
            }

            try
            {
                bool result;

                if (!audio.IsAddedByCurrentUser)
                {
                    result = await DataService.RemoveAudio(audio);
                }
                else
                    result = await DataService.AddAudio(audio, captchaSid, captchaKey);

                if (result)
                {
                    //нужно, чтобы обновить список треков пользователя, если он открыт в данный момент
                    MessengerInstance.Send(new UserTracksChangedMessage());
                }
                else
                {
                    audio.IsAddedByCurrentUser = !audio.IsAddedByCurrentUser;
                    LoggingService.Log("Can't add/remove audio " + audio.Id + " owner: " + audio.OwnerId + ".");
                }
            }
            catch (VkCaptchaNeededException ex)
            {
                LikeDislikeAudio(audio, true, ex.CaptchaSid, ex.CaptchaImg);
            }
            catch (Exception ex)
            {
                audio.IsAddedByCurrentUser = !audio.IsAddedByCurrentUser;
                LoggingService.Log(ex);
            }

            IsWorking = false;
        }
Esempio n. 12
0
        private async static void PlayInternal(Audio track, CancellationToken token)
        {
            if (CurrentAudio != null)
            {
                CurrentAudio.IsPlaying = false;

                Stop();
            }

            CurrentAudio = track;

            if (track.Url == null)
            {
                Audio vkAudio = null;
                try
                {
                    vkAudio = await DataService.GetAudioByArtistAndTitle(track.Artist, track.Title);
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }

                if (vkAudio != null)
                {
                    track.Id = vkAudio.Id;
                    track.Artist = vkAudio.Artist;
                    track.Title = vkAudio.Title;
                    track.Url = vkAudio.Url;
                    track.OwnerId = vkAudio.OwnerId;
                    track.AlbumId = vkAudio.AlbumId;
                    track.LyricsId = vkAudio.LyricsId;

                    _playFailsCount = 0;
                }
                else
                {
                    LoggingService.Log("Failed to find audio " + track.Artist + " - " + track.Title);

                    _playFailsCount++;
                    if (_playFailsCount > 5)
                        return;

                    if (RadioService.CurrentRadio == null)
                        Next();
                    else
                        RadioService.InvalidateCurrentSong();

                    return;
                }
            }

#if DEBUG
            LoggingService.Log(string.Format("Playing: {0} {1} {2} {3}", track.Id + "_" + track.OwnerId, track.Artist, track.Title, track.Url));
#endif

            if (token.IsCancellationRequested)
                return;

            track.IsPlaying = true;
            //похоже что MediaElement не умеет https, поэтому временный хак
            var url = track.Url;
            url = url.Replace("https://", "http://");

            MediaPlayer.Source = new Uri(url);
            MediaPlayer.Play();

            State = PlayerPlayState.Playing;
        }
Esempio n. 13
0
 public static void Play(Audio track)
 {
     CancelAsync();
     PlayInternal(track, _cancellationToken.Token);
 }
        public AddToAlbumView(Audio track)
        {
            _track = track;

            InitializeComponent();
        }
Esempio n. 15
0
        public static void PlayNext(Audio audio)
        {
            if (Playlist != null && CurrentAudio != null)
            {
                var currentAudio = Playlist.FirstOrDefault(a => a.Id == CurrentAudio.Id);
                if (currentAudio == null)
                    return;

                var index = Playlist.IndexOf(currentAudio);
                if (index >= 0)
                {
                    index++;
                    var newAudio = new Audio();
                    newAudio.Id = audio.Id;
                    newAudio.OwnerId = audio.OwnerId;
                    newAudio.Title = audio.Title;
                    newAudio.Artist = audio.Artist;
                    newAudio.AlbumId = audio.AlbumId;
                    newAudio.Duration = audio.Duration;
                    newAudio.IsAddedByCurrentUser = audio.IsAddedByCurrentUser;
                    newAudio.Url = audio.Url;
                    newAudio.Lyrics = audio.Lyrics;
                    newAudio.LyricsId = audio.LyricsId;
                    Playlist.Insert(index, newAudio);
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Returns a copy of current audio object
        /// </summary>
        /// <returns></returns>
        public virtual Audio Clone()
        {
            var audio = new Audio();
            audio.Id = this.Id;
            audio.Title = this.Title;
            audio.Artist = this.Artist;
            audio.Duration = this.Duration;
            audio.IsPlaying = this.IsPlaying;

            return audio;
        }
Esempio n. 17
0
 private static void NotifyAudioChanged(Audio oldAudio = null)
 {
     Messenger.Default.Send(new CurrentAudioChangedMessage
     {
         OldAudio = oldAudio,
         NewAudio = CurrentAudio
     });
 }
Esempio n. 18
0
        private void ShowTrackNotification(Audio track)
        {
            if (track == null)
                return;

            var w = CurrentUIMode == UIMode.Normal
                ? Application.Current.MainWindow
                : Application.Current.Windows.OfType<CompactView>().FirstOrDefault();

            if (w == null)
                return;

            if (w.IsActive &&
                w.WindowState != WindowState.Minimized)
                return;

            var notificationView = Application.Current.Windows.OfType<TrackNotifcationView>().FirstOrDefault();
            if (notificationView == null)
            {
                notificationView = new TrackNotifcationView(track);
                notificationView.Show();
            }
            else
            {
                notificationView.Track = track;
            }
        }
Esempio n. 19
0
        private void ShowTrackNotification(Audio track)
        {
            if (track == null)
                return;

            Window w;

            if (CurrentUIMode == UIMode.Normal)
                w = Application.Current.MainWindow;
            else
            {
                var t = CurrentUIMode == UIMode.CompactLandscape ? typeof(CompactLandscapeView) : typeof(CompactView);
                w = CurrentUIMode == UIMode.CompactLandscape
                    ? (Window)Application.Current.Windows.OfType<CompactLandscapeView>().FirstOrDefault()
                    : (Window)Application.Current.Windows.OfType<CompactView>().FirstOrDefault();
            }

            if (w == null)
                return;

            if (w.IsActive &&
                w.WindowState != WindowState.Minimized)
                return;

            var notificationView = Application.Current.Windows.OfType<TrackNotifcationView>().FirstOrDefault();
            if (notificationView == null)
            {
                notificationView = new TrackNotifcationView(track);
                notificationView.Show();
            }
            else
            {
                notificationView.Track = track;
            }
        }