Implemented basic Icarus functionality. Will continue to improve on it. Need to work on updating the song view when returning from the player. #49
This commit is contained in:
@@ -57,29 +57,6 @@ namespace Mear.Playback
|
||||
await CrossMediaManager.Current.Play(tmpFile);
|
||||
song.SongPath = tmpFile;
|
||||
|
||||
for (var atmpt = 0; !CrossMediaManager.Current.IsPlaying(); atmpt++)
|
||||
{
|
||||
if (atmpt == 5)
|
||||
{
|
||||
break;
|
||||
}
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
if (CrossMediaManager.Current.IsPlaying())
|
||||
{
|
||||
var plyCountRepo = new DBPlayCountRepository();
|
||||
var plyCount = plyCountRepo.RetrievePlayCount(song.Id);
|
||||
|
||||
if (plyCount == null)
|
||||
{
|
||||
plyCountRepo.SavePlayCount(song);
|
||||
}
|
||||
else
|
||||
{
|
||||
plyCountRepo.UpdatePlayCount(song);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return song;
|
||||
@@ -98,21 +75,6 @@ namespace Mear.Playback
|
||||
var songPath = song.SongPath;
|
||||
|
||||
await CrossMediaManager.Current.Play(songPath);
|
||||
|
||||
if (CrossMediaManager.Current.IsPlaying())
|
||||
{
|
||||
var plyCountRepo = new DBPlayCountRepository();
|
||||
var plyCount = plyCountRepo.RetrievePlayCount(song.Id);
|
||||
|
||||
if (plyCount == null)
|
||||
{
|
||||
plyCountRepo.SavePlayCount(song);
|
||||
}
|
||||
else
|
||||
{
|
||||
plyCountRepo.UpdatePlayCount(song);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -49,6 +49,48 @@ namespace Mear.Repositories.Database
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AffectPlayCount(Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!DoesTableExist("PlayCount"))
|
||||
{
|
||||
_Db.CreateTable<PlayCount>();
|
||||
}
|
||||
else
|
||||
{
|
||||
var plyCount = RetrievePlayCount(song);
|
||||
if (plyCount == null)
|
||||
{
|
||||
_Db.Insert(new PlayCount
|
||||
{
|
||||
PlayCounter = 1,
|
||||
SongId = song.Id
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_Db.Update(plyCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
}
|
||||
public void DeletePlayCount(Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
var plyCount = RetrievePlayCount(song);
|
||||
_Db.Delete(plyCount);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
}
|
||||
public void SavePlayCount(Song song)
|
||||
{
|
||||
try
|
||||
@@ -91,6 +133,31 @@ namespace Mear.Repositories.Database
|
||||
var msg = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private PlayCount RetrievePlayCount(Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DoesTableExist("PlayCount"))
|
||||
{
|
||||
var songId = song.Id;
|
||||
var playCount = _Db.Table<PlayCount>()
|
||||
.Where(p => p.SongId==songId).First();
|
||||
|
||||
if (playCount != null)
|
||||
{
|
||||
return playCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,17 @@ namespace Mear.Repositories.Database
|
||||
return null;
|
||||
}
|
||||
|
||||
public void DeleteSong(Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
_Db.Delete(song);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
}
|
||||
}
|
||||
public void SaveSong(Song song)
|
||||
{
|
||||
if (!DoesTableExist("Song"))
|
||||
|
||||
@@ -68,7 +68,6 @@
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Name="Download" Order="Secondary" Priority="1" Clicked="Download_Clicked" />
|
||||
<ToolbarItem Name="PlayCount" Order="Secondary" Priority="2" Clicked="PlayCount_Clicked" />
|
||||
</ContentPage.ToolbarItems>
|
||||
</ContentPage>
|
||||
@@ -47,14 +47,34 @@ namespace Mear.Views
|
||||
BackgroundSongElasping();
|
||||
BackgroundSongCoverUpdate();
|
||||
|
||||
InitializeOptions();
|
||||
|
||||
BindingContext = _viewModel = new MearPlayerViewModel(song);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Methods
|
||||
private void Initialize()
|
||||
private void InitializeOptions()
|
||||
{
|
||||
if (!_song.Downloaded)
|
||||
{
|
||||
var dnloadOpt = new ToolbarItem();
|
||||
dnloadOpt.Text = "Download";
|
||||
dnloadOpt.Order = ToolbarItemOrder.Secondary;
|
||||
dnloadOpt.Priority = 1;
|
||||
dnloadOpt.Clicked += Download_Clicked;
|
||||
ToolbarItems.Add(dnloadOpt);
|
||||
}
|
||||
else
|
||||
{
|
||||
var rmvOpt = new ToolbarItem();
|
||||
rmvOpt.Text = "Remove";
|
||||
rmvOpt.Order = ToolbarItemOrder.Secondary;
|
||||
rmvOpt.Priority = 1;
|
||||
rmvOpt.Clicked += Remove_Clicked;
|
||||
ToolbarItems.Add(rmvOpt);
|
||||
}
|
||||
}
|
||||
private void InitializeControls()
|
||||
{
|
||||
@@ -164,6 +184,16 @@ namespace Mear.Views
|
||||
var songRepo = new RemoteSongRepository();
|
||||
songRepo.DownloadSong(_song);
|
||||
}
|
||||
private async void Remove_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
var dbSongRepo = new DBSongRepository();
|
||||
var plyCount = new DBPlayCountRepository();
|
||||
dbSongRepo.DeleteSong(_song);
|
||||
plyCount.DeletePlayCount(_song);
|
||||
_song.Downloaded = false;
|
||||
|
||||
File.Delete(_song.SongPath);
|
||||
}
|
||||
private async void PlayCount_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
var playCountRepo = new DBPlayCountRepository();
|
||||
|
||||
@@ -4,11 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using MediaManager;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using Mear.Models;
|
||||
using Mear.Playback;
|
||||
using Mear.Repositories.Database;
|
||||
using Mear.Repositories.Remote;
|
||||
using Mear.ViewModels;
|
||||
|
||||
@@ -57,8 +59,20 @@ namespace Mear.Views
|
||||
else
|
||||
{
|
||||
song = await MearPlayer.StreamSongDemoAsync(song);
|
||||
var plyCountRepo = new DBPlayCountRepository();
|
||||
plyCountRepo.AffectPlayCount(song);
|
||||
}
|
||||
await Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(song)));
|
||||
|
||||
while (true)
|
||||
{
|
||||
var buffering = CrossMediaManager.Current.IsBuffering();
|
||||
if (!buffering)
|
||||
{
|
||||
var yup = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(song)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user