diff --git a/Mear/Mear/Playback/MearPlayer.cs b/Mear/Mear/Playback/MearPlayer.cs index aec54ea..44e8a62 100644 --- a/Mear/Mear/Playback/MearPlayer.cs +++ b/Mear/Mear/Playback/MearPlayer.cs @@ -405,7 +405,14 @@ namespace Mear.Playback } var song = _mearQueue.ToArray()[_songIndex++]; - PlaySong(song.SongPath); + if (song.Downloaded) + { + PlaySong(song.SongPath); + } + else + { + StreamSong(song); + } } #endregion #endregion diff --git a/Mear/Mear/Views/AlbumView.xaml.cs b/Mear/Mear/Views/AlbumView.xaml.cs index de64c54..fe08681 100644 --- a/Mear/Mear/Views/AlbumView.xaml.cs +++ b/Mear/Mear/Views/AlbumView.xaml.cs @@ -19,7 +19,9 @@ namespace Mear.Views { #region Fields private StackLayout _playerIndicatorLayout; + private ProgressBar _songProgress; private Button _controlButton; + private Label _songArtistLabel; private Label _songTitleLabel; private AlbumViewModel _viewModel; #endregion @@ -33,15 +35,21 @@ namespace Mear.Views public AlbumView() { InitializeComponent(); - AddPlayerIndicator(); - BackgroundControl(); BindingContext = _viewModel = new AlbumViewModel(); + + Initialize(); } #endregion #region Methods + private async Task Initialize() + { + AddPlayerIndicator(); + BackgroundControl(); + BackgroundSongProgress(); + } private async Task AddPlayerIndicator() { var mainLayout = AlbumViewMainLayout; @@ -55,28 +63,53 @@ namespace Mear.Views private async Task ConfigureSongIndicatorLayout() { var indicatorLayout = new StackLayout(); + var songDetailLayout = new StackLayout(); indicatorLayout.Orientation = StackOrientation.Horizontal; + indicatorLayout.HorizontalOptions = LayoutOptions.Fill; + indicatorLayout.MinimumWidthRequest = 400; indicatorLayout.Padding = 5; + + _songProgress = new ProgressBar(); + _songProgress.HorizontalOptions = LayoutOptions.Fill; + _songProgress.MinimumWidthRequest = 400; + _songProgress.Progress = 0; + _controlButton = new Button(); _controlButton.Clicked += ControlButton_Clicked; _songTitleLabel = new Label(); - _songTitleLabel.HorizontalOptions = LayoutOptions.Center; + _songTitleLabel.FontSize = 13; + _songTitleLabel.HorizontalOptions = LayoutOptions.Start; _songTitleLabel.VerticalOptions = LayoutOptions.Start; + _songArtistLabel = new Label(); + _songArtistLabel.FontSize = 10; + var isSongPlayer = MearPlayer.IsPlaying(); if (isSongPlayer) { _controlButton.Text = "P"; - _songTitleLabel.Text = await MearPlayer.SongTitle(); + _songTitleLabel.Text = MearPlayer.OnSong.Title; + _songArtistLabel.Text = MearPlayer.OnSong.Artist; } else { _controlButton.Text = "S"; _songTitleLabel.Text = string.Empty; + _songArtistLabel.Text = string.Empty; } + _songTitleLabel.HorizontalOptions = LayoutOptions.Fill; + + var tapped = new TapGestureRecognizer(); + tapped.Tapped += OpenPlayer; + songDetailLayout.GestureRecognizers.Add(tapped); + + songDetailLayout.Children.Add(_songTitleLabel); + songDetailLayout.Children.Add(_songArtistLabel); + songDetailLayout.Children.Add(_songProgress); + indicatorLayout.Children.Add(_controlButton); - indicatorLayout.Children.Add(_songTitleLabel); + indicatorLayout.Children.Add(songDetailLayout); return indicatorLayout; } @@ -94,7 +127,8 @@ namespace Mear.Views { if (MearPlayer.SongHasBeenChanged(MearPlayer.MusicViews.Album)) { - _songTitleLabel.Text = MearPlayer.SongTitle().Result; + _songTitleLabel.Text = MearPlayer.OnSong.Title; + _songArtistLabel.Text = MearPlayer.OnSong.Artist; MearPlayer.ResetSongChange(MearPlayer.MusicViews.Album); } }); @@ -107,9 +141,42 @@ namespace Mear.Views var msg = ex.Message; } } + private async Task BackgroundSongProgress() + { + try + { + new Thread(async () => + { + while (true) + { + Device.BeginInvokeOnMainThread(async () => + { + var progress = MearPlayer.ProgressValue().Result; + if (progress != null) + { + _songProgress.Progress = progress.Value / 100.0; + } + }); + + await Task.Delay(250); + } + }).Start(); + } + catch (Exception ex) + { + var msg = ex.Message; + } + } #endregion #region Events + private async void OpenPlayer(object sender, EventArgs e) + { + if (MearPlayer.IsPlaying()) + { + Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(MearPlayer.OnSong))); + } + } private async void ControlButton_Clicked(object sender, EventArgs e) { if (MearPlayer.IsPlaying()) diff --git a/Mear/Mear/Views/ArtistView.xaml.cs b/Mear/Mear/Views/ArtistView.xaml.cs index 55d448f..5d355be 100644 --- a/Mear/Mear/Views/ArtistView.xaml.cs +++ b/Mear/Mear/Views/ArtistView.xaml.cs @@ -19,7 +19,9 @@ namespace Mear.Views { #region Fields private StackLayout _playerIndicatorLayout; + private ProgressBar _songProgress; private Button _controlButton; + private Label _songArtistLabel; private Label _songTitleLabel; private ArtistViewModel _viewModel; #endregion @@ -33,8 +35,7 @@ namespace Mear.Views public ArtistView() { InitializeComponent(); - AddPlayerIndicator(); - BackgroundControl(); + Initialize(); BindingContext = _viewModel = new ArtistViewModel(); } @@ -42,6 +43,12 @@ namespace Mear.Views #region Methods + private async Task Initialize() + { + AddPlayerIndicator(); + BackgroundControl(); + BackgroundSongProgress(); + } private async Task AddPlayerIndicator() { var mainLayout = ArtistViewMainLayout; @@ -55,28 +62,54 @@ namespace Mear.Views private async Task ConfigureSongIndicatorLayout() { var indicatorLayout = new StackLayout(); + var songDetailLayout = new StackLayout(); + songDetailLayout.Orientation = StackOrientation.Vertical; indicatorLayout.Orientation = StackOrientation.Horizontal; + indicatorLayout.HorizontalOptions = LayoutOptions.Fill; + indicatorLayout.MinimumWidthRequest = 400; indicatorLayout.Padding = 5; + + _songProgress = new ProgressBar(); + _songProgress.HorizontalOptions = LayoutOptions.Fill; + _songProgress.MinimumWidthRequest = 400; + _songProgress.Progress = 0; + _controlButton = new Button(); _controlButton.Clicked += ControlButton_Clicked; _songTitleLabel = new Label(); - _songTitleLabel.HorizontalOptions = LayoutOptions.Center; + _songTitleLabel.FontSize = 13; + _songTitleLabel.HorizontalOptions = LayoutOptions.Start; _songTitleLabel.VerticalOptions = LayoutOptions.Start; + _songArtistLabel = new Label(); + _songArtistLabel.FontSize = 10; + var isSongPlayer = MearPlayer.IsPlaying(); if (isSongPlayer) { _controlButton.Text = "P"; - _songTitleLabel.Text = await MearPlayer.SongTitle(); + _songTitleLabel.Text = MearPlayer.OnSong.Title; + _songArtistLabel.Text = MearPlayer.OnSong.Artist; } else { _controlButton.Text = "S"; _songTitleLabel.Text = string.Empty; + _songArtistLabel.Text = string.Empty; } + _songTitleLabel.HorizontalOptions = LayoutOptions.Fill; + + var tapped = new TapGestureRecognizer(); + tapped.Tapped += OpenPlayer; + songDetailLayout.GestureRecognizers.Add(tapped); + + songDetailLayout.Children.Add(_songTitleLabel); + songDetailLayout.Children.Add(_songArtistLabel); + songDetailLayout.Children.Add(_songProgress); + indicatorLayout.Children.Add(_controlButton); - indicatorLayout.Children.Add(_songTitleLabel); + indicatorLayout.Children.Add(songDetailLayout); return indicatorLayout; } @@ -94,7 +127,8 @@ namespace Mear.Views { if (MearPlayer.SongHasBeenChanged(MearPlayer.MusicViews.Artist)) { - _songTitleLabel.Text = MearPlayer.SongTitle().Result; + _songTitleLabel.Text = MearPlayer.OnSong.Title; + _songArtistLabel.Text = MearPlayer.OnSong.Artist; MearPlayer.ResetSongChange(MearPlayer.MusicViews.Artist); } }); @@ -107,9 +141,42 @@ namespace Mear.Views var msg = ex.Message; } } + private async Task BackgroundSongProgress() + { + try + { + new Thread(async () => + { + while (true) + { + Device.BeginInvokeOnMainThread(async () => + { + var progress = MearPlayer.ProgressValue().Result; + if (progress != null) + { + _songProgress.Progress = progress.Value / 100.0; + } + }); + + await Task.Delay(250); + } + }).Start(); + } + catch (Exception ex) + { + var msg = ex.Message; + } + } #endregion #region Events + private async void OpenPlayer(object sender, EventArgs e) + { + if (MearPlayer.IsPlaying()) + { + Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(MearPlayer.OnSong))); + } + } private async void ControlButton_Clicked(object sender, EventArgs e) { if (MearPlayer.IsPlaying()) diff --git a/Mear/Mear/Views/MearPlayerView.xaml.cs b/Mear/Mear/Views/MearPlayerView.xaml.cs index 5838867..865090d 100644 --- a/Mear/Mear/Views/MearPlayerView.xaml.cs +++ b/Mear/Mear/Views/MearPlayerView.xaml.cs @@ -46,6 +46,17 @@ namespace Mear.Views { InitializeComponent(); MearPlayer.OnSong = song; + + Initialize(); + + BindingContext = _viewModel = new MearPlayerViewModel(song); + } + #endregion + + + #region Methods + private async Task Initialize() + { InitializeControls(); BackgroundSongElasping(); @@ -54,13 +65,7 @@ namespace Mear.Views //BackgroundControlInit(); InitializeOptions(); - - BindingContext = _viewModel = new MearPlayerViewModel(song); - } - #endregion - - - #region Methods + } private ToolbarItem DownloadOption() { var dnloadOpt = new ToolbarItem(); @@ -117,14 +122,17 @@ namespace Mear.Views while (true) { Device.BeginInvokeOnMainThread(async () => - { - var curPos = await MearPlayer.ConvertToTime(); - StartTime.Text = $"{curPos}"; - double? progVal = await MearPlayer.ProgressValue(); - SongProgress.Value = progVal.Value; + { + if (MearPlayer.IsPlaying()) + { + var curPos = await MearPlayer.ConvertToTime(); + StartTime.Text = $"{curPos}"; + double? progVal = await MearPlayer.ProgressValue(); + SongProgress.Value = progVal.Value; + } }); - await Task.Delay(500); + await Task.Delay(250); } }).Start(); } diff --git a/Mear/Mear/Views/SongView.xaml.cs b/Mear/Mear/Views/SongView.xaml.cs index 8aeb02d..d0eb4d6 100644 --- a/Mear/Mear/Views/SongView.xaml.cs +++ b/Mear/Mear/Views/SongView.xaml.cs @@ -23,7 +23,9 @@ namespace Mear.Views { #region Fields private StackLayout _playerIndicatorLayout; + private ProgressBar _songProgress; private Button _controlButton; + private Label _songArtistLabel; private Label _songTitleLabel; private SongViewModel _viewModel; #endregion @@ -39,13 +41,19 @@ namespace Mear.Views InitializeComponent(); BindingContext = _viewModel = new SongViewModel(); - AddPlayerIndicator(); - BackgroundControl(); + + Initialize(); } #endregion #region Methods + private async Task Initialize() + { + AddPlayerIndicator(); + BackgroundControl(); + BackgroundSongProgress(); + } private async Task AddPlayerIndicator() { var mainLayout = SongViewMainLayout; @@ -59,33 +67,66 @@ namespace Mear.Views private async Task ConfigureSongIndicatorLayout() { var indicatorLayout = new StackLayout(); + var songDetailLayout = new StackLayout(); + songDetailLayout.Orientation = StackOrientation.Vertical; indicatorLayout.Orientation = StackOrientation.Horizontal; + indicatorLayout.HorizontalOptions = LayoutOptions.Fill; + indicatorLayout.MinimumWidthRequest = 400; indicatorLayout.Padding = 5; + + _songProgress = new ProgressBar(); + _songProgress.HorizontalOptions = LayoutOptions.Fill; + _songProgress.MinimumWidthRequest = 400; + _songProgress.Progress = 0; + _controlButton = new Button(); _controlButton.Clicked += ControlButton_Clicked; _songTitleLabel = new Label(); - _songTitleLabel.HorizontalOptions = LayoutOptions.Center; + _songTitleLabel.FontSize = 13; + _songTitleLabel.HorizontalOptions = LayoutOptions.Start; _songTitleLabel.VerticalOptions = LayoutOptions.Start; + _songArtistLabel = new Label(); + _songArtistLabel.FontSize = 10; + var isSongPlayer = MearPlayer.IsPlaying(); if (isSongPlayer) { _controlButton.Text = "P"; - _songTitleLabel.Text = await MearPlayer.SongTitle(); + _songTitleLabel.Text = MearPlayer.OnSong.Title; + _songArtistLabel.Text = MearPlayer.OnSong.Artist; } else { _controlButton.Text = "S"; _songTitleLabel.Text = string.Empty; + _songArtistLabel.Text = string.Empty; } + _songTitleLabel.HorizontalOptions = LayoutOptions.Fill; + + var tapped = new TapGestureRecognizer(); + tapped.Tapped += OpenPlayer; + songDetailLayout.GestureRecognizers.Add(tapped); + + songDetailLayout.Children.Add(_songTitleLabel); + songDetailLayout.Children.Add(_songArtistLabel); + songDetailLayout.Children.Add(_songProgress); + indicatorLayout.Children.Add(_controlButton); - indicatorLayout.Children.Add(_songTitleLabel); + indicatorLayout.Children.Add(songDetailLayout); return indicatorLayout; } #region Events + private async void OpenPlayer(object sender, EventArgs e) + { + if (MearPlayer.IsPlaying()) + { + Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(MearPlayer.OnSong))); + } + } private async void ControlButton_Clicked(object sender, EventArgs e) { if (MearPlayer.IsPlaying()) @@ -160,7 +201,8 @@ namespace Mear.Views { if (MearPlayer.SongHasBeenChanged(MearPlayer.MusicViews.Song)) { - _songTitleLabel.Text = MearPlayer.SongTitle().Result; + _songTitleLabel.Text = MearPlayer.OnSong.Title; + _songArtistLabel.Text = MearPlayer.OnSong.Artist; MearPlayer.ResetSongChange(MearPlayer.MusicViews.Song); } }); @@ -173,6 +215,32 @@ namespace Mear.Views var msg = ex.Message; } } + private async Task BackgroundSongProgress() + { + try + { + new Thread(async () => + { + while (true) + { + Device.BeginInvokeOnMainThread(async () => + { + var progress = MearPlayer.ProgressValue().Result; + if (progress != null) + { + _songProgress.Progress = progress.Value / 100.0; + } + }); + + await Task.Delay(250); + } + }).Start(); + } + catch (Exception ex) + { + var msg = ex.Message; + } + } #endregion #region Test