Implemented Repeat functionality and started working on the Settings and the color scheme. #23, #35, #14, #5
This commit is contained in:
@@ -48,6 +48,9 @@
|
||||
<EmbeddedResource Update="Views\RegisterPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Update="Views\SettingsPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Update="Views\SongView.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using MediaManager;
|
||||
@@ -22,6 +23,7 @@ namespace Mear.Playback
|
||||
{
|
||||
#region Fields
|
||||
private static Song _song;
|
||||
private static bool? _initialized = null;
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -72,27 +74,16 @@ namespace Mear.Playback
|
||||
|
||||
return null;
|
||||
}
|
||||
public static async Task PlaySong(Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
var songPath = song.SongPath;
|
||||
|
||||
await CrossMediaManager.Current.Play(songPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
}
|
||||
public static async Task<Song> ControlMusic(Song song, PlayControls control)
|
||||
{
|
||||
|
||||
_song = song;
|
||||
switch (control)
|
||||
{
|
||||
case PlayControls.PLAYOFFLINE:
|
||||
var songPath = song.SongPath;
|
||||
await CrossMediaManager.Current.Play(songPath);
|
||||
await PlaySong(songPath);
|
||||
var plyCountRepo = new DBPlayCountRepository();
|
||||
plyCountRepo.AffectPlayCount(song);
|
||||
InitializeRepeatMode();
|
||||
break;
|
||||
case PlayControls.PAUSE:
|
||||
@@ -122,23 +113,97 @@ namespace Mear.Playback
|
||||
return null;
|
||||
}
|
||||
|
||||
public static async Task<string> ConvertToTime()
|
||||
{
|
||||
try
|
||||
{
|
||||
var ttlSec = (int)CrossMediaManager.Current.Position.TotalSeconds;
|
||||
var cnvrt = new TimeFormat();
|
||||
var curPos = cnvrt.ConvertToSongTime(ttlSec);
|
||||
|
||||
return curPos;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static async Task<double?> ProgressValue()
|
||||
{
|
||||
try
|
||||
{
|
||||
var totalSeconds = (int)CrossMediaManager.Current.Position.TotalSeconds;
|
||||
double progVal = ((double)totalSeconds) / ((double)_song.Duration) * 100;
|
||||
|
||||
return progVal;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static async Task PlaySong(Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
var songPath = song.SongPath;
|
||||
|
||||
await CrossMediaManager.Current.Play(songPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
}
|
||||
public static async Task SeekTo(double songProress)
|
||||
{
|
||||
double newPosition = (songProress / 100) * ((double)_song.Duration);
|
||||
await CrossMediaManager.Current.SeekTo(TimeSpan.FromSeconds(newPosition));
|
||||
}
|
||||
|
||||
public static string RetrieveRepeatString()
|
||||
{
|
||||
var ctrlRepeatMode = CrossMediaManager.Current.RepeatMode;
|
||||
var ctrlRepo = new DBMusicControlsRepository();
|
||||
var ctrlRepeatMode = ctrlRepo.IsRepeatOn();
|
||||
|
||||
switch (ctrlRepeatMode)
|
||||
{
|
||||
case MediaManager.Playback.RepeatMode.Off:
|
||||
case Repeat.OFF:
|
||||
return "RepOff";
|
||||
case MediaManager.Playback.RepeatMode.One:
|
||||
case Repeat.ONE:
|
||||
return "RepOn";
|
||||
case MediaManager.Playback.RepeatMode.All:
|
||||
case Repeat.ALL:
|
||||
return "RepAll";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static bool IsPlaying()
|
||||
{
|
||||
return CrossMediaManager.Current.IsPlaying();
|
||||
}
|
||||
public static bool RepeatMatchedDatabase()
|
||||
{
|
||||
var playerRepeatMode = CrossMediaManager.Current.RepeatMode;
|
||||
var controlRepo = new DBMusicControlsRepository();
|
||||
var repeatMode = controlRepo.IsRepeatOn();
|
||||
var repeatModeConverted = RepeatUtility.RetrieveRepeatMode(repeatMode);
|
||||
|
||||
return (playerRepeatMode == repeatModeConverted);
|
||||
}
|
||||
|
||||
public static void UpdateRepeatControls()
|
||||
{
|
||||
InitializeRepeatMode();
|
||||
}
|
||||
|
||||
private static Song StreamSong(Song song)
|
||||
{
|
||||
string tmpFile = Path.GetTempPath() + "track.mp3";
|
||||
@@ -196,19 +261,62 @@ namespace Mear.Playback
|
||||
private static async Task PlaySong(string songPath)
|
||||
{
|
||||
await CrossMediaManager.Current.Play(songPath);
|
||||
if (_initialized == null)
|
||||
{
|
||||
CrossMediaManager.Current.MediaItemFinished += Current_MediaItemFinished;
|
||||
//BackgroundWork();
|
||||
_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToggleRepeat()
|
||||
{
|
||||
var musicCtrl = new DBMusicControlsRepository();
|
||||
musicCtrl.UpdateRepeat();
|
||||
var repeatMode = (Repeat)musicCtrl.IsRepeatOn();
|
||||
|
||||
for (var rpt = RepeatUtility.RetrieveRepeatMode(repeatMode);
|
||||
CrossMediaManager.Current.RepeatMode != rpt;)
|
||||
CrossMediaManager.Current.RepeatMode = RepeatUtility.RetrieveRepeatMode(repeatMode);
|
||||
}
|
||||
|
||||
#region Background
|
||||
private static async Task BackgroundWork()
|
||||
{
|
||||
try
|
||||
{
|
||||
CrossMediaManager.Current.RepeatMode = RepeatUtility.RetrieveRepeatMode(repeatMode);
|
||||
new Thread(async () =>
|
||||
{
|
||||
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
private static void Current_MediaItemFinished(object sender, MediaManager.Media.MediaItemEventArgs e)
|
||||
{
|
||||
var ctrlRepo = new DBMusicControlsRepository();
|
||||
var repeatMode = ctrlRepo.IsRepeatOn();
|
||||
if (CrossMediaManager.Current.IsPlaying())
|
||||
{
|
||||
//return;
|
||||
}
|
||||
switch(repeatMode)
|
||||
{
|
||||
case Repeat.ONE:
|
||||
CrossMediaManager.Current.SeekToStart();
|
||||
//PlaySong(_song.SongPath);
|
||||
break;
|
||||
case Repeat.ALL:
|
||||
// Will implment this fully later once Queues are a feature
|
||||
PlaySong(_song.SongPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Mear.ViewModels
|
||||
{
|
||||
public class SettingsViewModel : BaseViewModel
|
||||
{
|
||||
#region Fields
|
||||
private ObservableCollection<SwitchItem> _switchItems;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
public ObservableCollection<SwitchItem> SwitchItems
|
||||
{
|
||||
get => _switchItems;
|
||||
set => _switchItems = value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public SettingsViewModel()
|
||||
{
|
||||
_switchItems = new ObservableCollection<SwitchItem>();
|
||||
|
||||
PopulateSwitch();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Methods
|
||||
private SwitchItem RetrieveColorSchemeSwitch()
|
||||
{
|
||||
var colorScheme = new SwitchItem
|
||||
{
|
||||
Title = "Dark Theme",
|
||||
IsOn = true
|
||||
};
|
||||
|
||||
return colorScheme;
|
||||
}
|
||||
private void PopulateSwitch()
|
||||
{
|
||||
var colorScheme = RetrieveColorSchemeSwitch();
|
||||
_switchItems.Add(colorScheme);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Classes
|
||||
public class SwitchItem
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public bool IsOn { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,6 @@ namespace Mear.Views
|
||||
AccessToken = loginRes.Token,
|
||||
UserId = loginRes.UserId
|
||||
});
|
||||
await DisplayAlert("Icarus Login", "Successfully logged in", "Ok");
|
||||
App.Current.MainPage = new MusicLibrary();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -51,6 +51,7 @@ namespace Mear.Views
|
||||
|
||||
BackgroundSongElasping();
|
||||
BackgroundSongCoverUpdate();
|
||||
//BackgroundControlInit();
|
||||
|
||||
InitializeOptions();
|
||||
|
||||
@@ -101,7 +102,6 @@ namespace Mear.Views
|
||||
|
||||
var controlRepo = new DBMusicControlsRepository();
|
||||
var shuffleOn = controlRepo.IsShuffleOn();
|
||||
var repeatMode = (RepeatMode)controlRepo.IsRepeatOn();
|
||||
|
||||
Shuffle.Text = (shuffleOn) ? "ShfOn" : "ShfOff";
|
||||
Repeat.Text = MearPlayer.RetrieveRepeatString();
|
||||
@@ -118,15 +118,12 @@ namespace Mear.Views
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
var ttlSec = (int)CrossMediaManager.Current.Position.TotalSeconds;
|
||||
var cnvrt = new TimeFormat();
|
||||
var curPos = cnvrt.ConvertToSongTime(ttlSec);
|
||||
var curPos = await MearPlayer.ConvertToTime();
|
||||
StartTime.Text = $"{curPos}";
|
||||
double progVal = ((double)ttlSec) / ((double)_song.Duration);
|
||||
progVal *= 100;
|
||||
SongProgress.Value = progVal;
|
||||
double? progVal = await MearPlayer.ProgressValue();
|
||||
SongProgress.Value = progVal.Value;
|
||||
});
|
||||
|
||||
await Task.Delay(500);
|
||||
@@ -144,7 +141,8 @@ namespace Mear.Views
|
||||
{
|
||||
new Thread(async () =>
|
||||
{
|
||||
while (true)
|
||||
// Will work on this later so I am setting it to false
|
||||
while (false)
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
@@ -164,6 +162,26 @@ namespace Mear.Views
|
||||
var msg = ex.Message;
|
||||
}
|
||||
}
|
||||
// Addresses issue where the Player's controls have not been properly initialized
|
||||
private async Task BackgroundControlInit()
|
||||
{
|
||||
try
|
||||
{
|
||||
new Thread(async () =>
|
||||
{
|
||||
while (!MearPlayer.RepeatMatchedDatabase())
|
||||
{
|
||||
MearPlayer.UpdateRepeatControls();
|
||||
Repeat.Text = MearPlayer.RetrieveRepeatString();
|
||||
await Task.Delay(750);
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
@@ -188,11 +206,7 @@ namespace Mear.Views
|
||||
}
|
||||
private void Repeat_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await MearPlayer.ControlMusic(_song, PlayControls.REPEAT);
|
||||
}).Wait();
|
||||
|
||||
MearPlayer.ControlMusic(_song, PlayControls.REPEAT);
|
||||
Repeat.Text = MearPlayer.RetrieveRepeatString();
|
||||
}
|
||||
private void Shuffle_Clicked(object sender, EventArgs e)
|
||||
@@ -208,8 +222,7 @@ namespace Mear.Views
|
||||
private async void SongProgress_DragCompleted(object sender, EventArgs e)
|
||||
{
|
||||
var progVal = SongProgress.Value;
|
||||
double newPos = (progVal / 100) * ((double)_song.Duration);
|
||||
await CrossMediaManager.Current.SeekTo(TimeSpan.FromSeconds(newPos));
|
||||
await MearPlayer.SeekTo(progVal);
|
||||
}
|
||||
|
||||
private void Download_Clicked(object sender, EventArgs e)
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace Mear.Views
|
||||
}
|
||||
private void Settings_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
Navigation.PushModalAsync(new NavigationPage(new SettingsPage()));
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
x:Class="Mear.Views.SettingsPage"
|
||||
xmlns:vm="clr-namespace:Mear.ViewModels"
|
||||
Title="Settings" >
|
||||
|
||||
<ContentPage.Content>
|
||||
<StackLayout>
|
||||
<ListView x:Name="Sliders"
|
||||
ItemsSource="{Binding SwitchItems}"
|
||||
HasUnevenRows="False"
|
||||
RowHeight="75" >
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<Grid MinimumHeightRequest="80" Padding="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackLayout Grid.Row="0" Grid.Column="0"
|
||||
Orientation="Horizontal">
|
||||
<Label Text="{Binding Title}"
|
||||
d:Text="{Binding .}"
|
||||
LineBreakMode="NoWrap"
|
||||
FontSize="14" />
|
||||
<Switch x:Name="{Binding Title}"
|
||||
IsToggled="{Binding On}"
|
||||
Toggled="Switch_Toggled" />
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using Mear.ViewModels;
|
||||
|
||||
namespace Mear.Views
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class SettingsPage : ContentPage
|
||||
{
|
||||
#region Fields
|
||||
private SettingsViewModel _viewModel;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public SettingsPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = _viewModel = new SettingsViewModel();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Methods
|
||||
#region Events
|
||||
private void Switch_Toggled(object sender, ToggledEventArgs e)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -60,20 +60,9 @@ namespace Mear.Views
|
||||
else
|
||||
{
|
||||
song = await MearPlayer.ControlMusic(song, PlayControls.STREAM);
|
||||
var plyCountRepo = new DBPlayCountRepository();
|
||||
plyCountRepo.AffectPlayCount(song);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
var buffering = CrossMediaManager.Current.IsBuffering();
|
||||
if (!buffering)
|
||||
{
|
||||
var yup = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(song)));
|
||||
Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(song)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user