Esempio n. 1
0
        /// <summary>
        /// Load state
        /// </summary>
        public async Task LoadState()
        {
            try
            {
                if (!FileStorageHelper.IsFileExists("currentPlaylist.js"))
                {
                    return;
                }

                var json = await FileStorageHelper.ReadText("currentPlaylist.js");

                if (!string.IsNullOrEmpty(json))
                {
                    _currentPlaylist.Deserialize(json);

                    if (_currentPlaylist.CurrentItem != null)
                    {
                        UpdateTransportControl();
                        CurrentAudioChanged?.Invoke(this, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to load AudioService state");
            }
        }
Esempio n. 2
0
        private void CurrentPlaylistOnCurrentItemChanged(object sender, IAudio audio)
        {
            Pause();
            Seek(TimeSpan.Zero);

            UpdateTransportControl();

            if (audio == null)
            {
                return;
            }

            if (audio.Source != null)
            {
                PlayFrom(audio.Source);

                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    CurrentAudioChanged?.Invoke(this, EventArgs.Empty);
                });
            }
            else
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    CurrentAudioChanged?.Invoke(this, EventArgs.Empty);
                });

                TryResolveTrack(audio);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Sets current playlist. Used to update UI on the first data load.
        /// </summary>
        public void SetCurrentPlaylist(AudioPlaylist playlist)
        {
            if (_currentPlaylist != null)
            {
                _currentPlaylist.OnCurrentItemChanged -= CurrentPlaylistOnCurrentItemChanged;
            }

            _currentPlaylist = playlist;

            if (_currentPlaylist != null)
            {
                _currentPlaylist.Repeat  = Repeat;
                _currentPlaylist.Shuffle = Shuffle;

                _currentPlaylist.OnCurrentItemChanged += CurrentPlaylistOnCurrentItemChanged;

                CurrentAudioChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Esempio n. 4
0
        private void CurrentPlaylistOnOnCurrentItemChanged(object sender, AudioFile args)
        {
            currentTrack = args;
            CurrentAudioChanged?.Invoke(this, args);
            TaskService.RunOnUI(async() =>
            {
                var media         = await player.Play(currentTrack.SourceString);
                media.MediaUri    = currentTrack.SourceString;
                media.Title       = currentTrack.Title;
                media.AlbumArtUri = ""; //Без этого треки с битыми ссылками будут выкидывать плеер в фатал
                media.Artist      = currentTrack.Artist;
                media.AlbumArtist = currentTrack.Artist;
                media.ArtUri      = null;
                if (currentTrack.Cover != "placeholder")
                {
                    media.ArtUri = currentTrack.Cover;
                }

                CrossMediaManager.Android.NotificationManager.UpdateNotification();
            });
            //Play(audio: args);
            CurrentAudioChanged?.Invoke(this, args);
            //throw new NotImplementedException();
        }
Esempio n. 5
0
        public void Play(PlaylistFile playlist = null, AudioFile audio = null)
        {
            //EndsWith(".mp3")
            if (audio.SourceString.Split("//")[1].Split("/")[0].EndsWith(".mp3"))
            {
                Toast.MakeText(Application.Context, "URI трека пришел с ошибкой. Невозможно воспроизвести.", ToastLength.Long).Show();
                return;
            }

            if (playlist == null)
            {
                if (currentPlaylist == null && currentTrack == null)
                {
                    return;
                }
                player.Play();
            }
            else
            {
                if (playlist.Id != currentPlaylistId)
                {
                    var audioPlaylist = new AudioPlaylist(playlist, audio, StaticContentService.RepeatPlaylist, StaticContentService.RepeatTrack);
                    currentPlaylist = audioPlaylist;
                    currentTrack    = audio;
                    currentPlaylist.OnCurrentItemChanged += CurrentPlaylistOnOnCurrentItemChanged;
                    CurrentAudioChanged?.Invoke(this, audio);
                }
                else
                {
                    currentPlaylist.SetCurrentTrack(audio);
                    currentTrack = audio;
                    CurrentAudioChanged?.Invoke(this, audio);
                }
                //var playerNotificationManager = (CrossMediaManager.Android.NotificationManager as MediaManager.Platforms.Android.Notifications.NotificationManager).PlayerNotificationManager;


                TaskService.RunOnUI(async() =>
                {
                    Toast.MakeText(Application.Context, "[Отладка] Начинаем воспроизводить...", ToastLength.Long).Show();
                    Toast.MakeText(Application.Context, $"[Отладка] URI: {currentTrack.SourceString}", ToastLength.Long).Show();
                    var media         = await player.Play(currentTrack.SourceString);
                    media.Title       = currentTrack.Title;
                    media.AlbumArtUri = ""; //Без этого треки с битыми ссылками будут выкидывать плеер в фатал
                    media.Artist      = currentTrack.Artist;
                    media.AlbumArtist = currentTrack.Artist;
                    media.ArtUri      = null;
                    if (currentTrack.Cover != "placeholder")
                    {
                        media.ArtUri = currentTrack.Cover;
                    }
                    CrossMediaManager.Android.NotificationManager.UpdateNotification();
                });


                //player.MediaQueue.Current.Title = audio.Title;
                //player.MediaQueue.Current.Artist = audio.Title;
                //player.MediaQueue.Current.AlbumArtUri = audio.Cover;
                //CrossMediaManager.Android.
                //player.NotificationManager = null;
            }
        }