Queue system is functioning #39
This commit is contained in:
@@ -29,7 +29,6 @@ namespace Mear.Droid
|
|||||||
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
|
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
|
||||||
LoadApplication(new App());
|
LoadApplication(new App());
|
||||||
|
|
||||||
CrossMediaManager.Current.Init();
|
|
||||||
CrossMediaManager.Current.Init(this);
|
CrossMediaManager.Current.Init(this);
|
||||||
}
|
}
|
||||||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
|
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -43,6 +44,30 @@ namespace Mear.Playback
|
|||||||
get => _song;
|
get => _song;
|
||||||
set => _song = value;
|
set => _song = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int QueueIndex
|
||||||
|
{
|
||||||
|
get => _songIndex;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value >= QueueCount)
|
||||||
|
{
|
||||||
|
_songIndex = 0;
|
||||||
|
}
|
||||||
|
else if (value < 0)
|
||||||
|
{
|
||||||
|
_songIndex = QueueCount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_songIndex = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static int QueueCount
|
||||||
|
{
|
||||||
|
get => _mearQueue.Count;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -51,44 +76,6 @@ namespace Mear.Playback
|
|||||||
|
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
public static async Task<Song> StreamSongDemoAsync(Song song)
|
|
||||||
{
|
|
||||||
string tmpFile = Path.GetTempPath() + "track.mp3";
|
|
||||||
|
|
||||||
if (File.Exists(tmpFile))
|
|
||||||
{
|
|
||||||
File.Delete(tmpFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var writer = File.OpenWrite(tmpFile))
|
|
||||||
{
|
|
||||||
var client = new RestClient(API.ApiUrl);
|
|
||||||
var apiEndpoint = $@"api/{API.APIVersion}/song/stream/{song.Id}"; ;
|
|
||||||
var request = new RestRequest(apiEndpoint, Method.GET);
|
|
||||||
var tokRepo = new DBTokenRepository();
|
|
||||||
var token = tokRepo.RetrieveToken();
|
|
||||||
request.AddHeader("Authorization", $"Bearer {token.AccessToken}");
|
|
||||||
request.ResponseWriter = (responseStream) =>
|
|
||||||
responseStream.CopyTo(writer);
|
|
||||||
|
|
||||||
var response = client.DownloadData(request);
|
|
||||||
|
|
||||||
await CrossMediaManager.Current.Play(tmpFile);
|
|
||||||
song.SongPath = tmpFile;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var msg = ex.Message;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public static async Task<Song> ControlMusic(Song song, PlayControls control)
|
public static async Task<Song> ControlMusic(Song song, PlayControls control)
|
||||||
{
|
{
|
||||||
if (song != null)
|
if (song != null)
|
||||||
@@ -98,7 +85,7 @@ namespace Mear.Playback
|
|||||||
switch (control)
|
switch (control)
|
||||||
{
|
{
|
||||||
case PlayControls.PLAYOFFLINE:
|
case PlayControls.PLAYOFFLINE:
|
||||||
await PlaySong(song);
|
DeterminePlayType();
|
||||||
var plyCountRepo = new DBPlayCountRepository();
|
var plyCountRepo = new DBPlayCountRepository();
|
||||||
plyCountRepo.AffectPlayCount(song);
|
plyCountRepo.AffectPlayCount(song);
|
||||||
InitializeRepeatMode();
|
InitializeRepeatMode();
|
||||||
@@ -110,9 +97,8 @@ namespace Mear.Playback
|
|||||||
ResumeSong();
|
ResumeSong();
|
||||||
break;
|
break;
|
||||||
case PlayControls.STREAM:
|
case PlayControls.STREAM:
|
||||||
song = StreamSong(song);
|
|
||||||
InitializeRepeatMode();
|
InitializeRepeatMode();
|
||||||
return song;
|
return StreamSong(song);
|
||||||
case PlayControls.REPEAT:
|
case PlayControls.REPEAT:
|
||||||
ToggleRepeat();
|
ToggleRepeat();
|
||||||
break;
|
break;
|
||||||
@@ -120,30 +106,22 @@ namespace Mear.Playback
|
|||||||
// TODO: Implement shuffling
|
// TODO: Implement shuffling
|
||||||
break;
|
break;
|
||||||
case PlayControls.NEXT:
|
case PlayControls.NEXT:
|
||||||
song = _mearQueue.ToArray()[_songIndex++];
|
_song = _mearQueue.ToArray()[++QueueIndex];
|
||||||
if (!song.Downloaded)
|
DeterminePlayType();
|
||||||
{
|
|
||||||
song = StreamSong(song);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PlaySong(song.SongPath);
|
|
||||||
}
|
|
||||||
_song = song;
|
|
||||||
_songChanged[MusicViews.Player] = true;
|
_songChanged[MusicViews.Player] = true;
|
||||||
break;
|
break;
|
||||||
case PlayControls.PREVIOUS:
|
case PlayControls.PREVIOUS:
|
||||||
|
_song = _mearQueue.ToArray()[--QueueIndex];
|
||||||
|
DeterminePlayType();
|
||||||
|
|
||||||
|
_songChanged[MusicViews.Player] = true;
|
||||||
break;
|
break;
|
||||||
// TODO: Implement Next
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string> SongTitle()
|
|
||||||
{
|
|
||||||
return _song.Title;
|
|
||||||
}
|
|
||||||
public static async Task<string> ConvertToTime()
|
public static async Task<string> ConvertToTime()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -176,6 +154,11 @@ namespace Mear.Playback
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task AlterIndex(Song song)
|
||||||
|
{
|
||||||
|
QueueIndex = _mearQueue.ToArray().ToList().IndexOf(song);
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task LoadQueue(List<Song> songs)
|
public static async Task LoadQueue(List<Song> songs)
|
||||||
{
|
{
|
||||||
if (_mearQueue == null)
|
if (_mearQueue == null)
|
||||||
@@ -193,19 +176,6 @@ namespace Mear.Playback
|
|||||||
|
|
||||||
_song.Downloaded = true;
|
_song.Downloaded = true;
|
||||||
}
|
}
|
||||||
public static async Task PlaySong(Song song)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var songPath = song.SongPath;
|
|
||||||
|
|
||||||
PlaySong(songPath);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var msg = ex.Message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static async Task RemoveSongFromFS()
|
public static async Task RemoveSongFromFS()
|
||||||
{
|
{
|
||||||
var dbSongRepo = new DBSongRepository();
|
var dbSongRepo = new DBSongRepository();
|
||||||
@@ -324,6 +294,17 @@ namespace Mear.Playback
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void DeterminePlayType()
|
||||||
|
{
|
||||||
|
if (!_song.Downloaded)
|
||||||
|
{
|
||||||
|
StreamSong(_song);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlaySong(_song.SongPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
private static void InitializeModes()
|
private static void InitializeModes()
|
||||||
{
|
{
|
||||||
InitializeRepeatMode();
|
InitializeRepeatMode();
|
||||||
@@ -396,15 +377,13 @@ namespace Mear.Playback
|
|||||||
CrossMediaManager.Current.SeekToStart();
|
CrossMediaManager.Current.SeekToStart();
|
||||||
PlaySong(_song.SongPath);
|
PlaySong(_song.SongPath);
|
||||||
return;
|
return;
|
||||||
break;
|
|
||||||
case Repeat.ALL:
|
case Repeat.ALL:
|
||||||
// Will implment this fully later once Queues are a feature
|
// Will implment this fully later once Queues are a feature
|
||||||
PlaySong(_song.SongPath);
|
PlaySong(_song.SongPath);
|
||||||
return;
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var song = _mearQueue.ToArray()[_songIndex++];
|
var song = _mearQueue.ToArray()[++QueueIndex];
|
||||||
if (song.Downloaded)
|
if (song.Downloaded)
|
||||||
{
|
{
|
||||||
PlaySong(song.SongPath);
|
PlaySong(song.SongPath);
|
||||||
@@ -413,6 +392,8 @@ namespace Mear.Playback
|
|||||||
{
|
{
|
||||||
StreamSong(song);
|
StreamSong(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_songChanged[MusicViews.Player] = true;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ namespace Mear.Views
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
MearPlayer.OnSong = song;
|
MearPlayer.OnSong = song;
|
||||||
|
|
||||||
Initialize();
|
|
||||||
|
|
||||||
BindingContext = _viewModel = new MearPlayerViewModel(song);
|
BindingContext = _viewModel = new MearPlayerViewModel(song);
|
||||||
|
|
||||||
|
Initialize();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ namespace Mear.Views
|
|||||||
#region Events
|
#region Events
|
||||||
private void Previous_Clicked(object sender, EventArgs e)
|
private void Previous_Clicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
MearPlayer.ControlMusic(null, PlayControls.PREVIOUS);
|
||||||
}
|
}
|
||||||
private async void Play_Clicked(object sender, EventArgs e)
|
private async void Play_Clicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -159,6 +159,8 @@ namespace Mear.Views
|
|||||||
song = await MearPlayer.ControlMusic(song, PlayControls.STREAM);
|
song = await MearPlayer.ControlMusic(song, PlayControls.STREAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MearPlayer.AlterIndex(song);
|
||||||
|
|
||||||
Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(song)));
|
Navigation.PushModalAsync(new NavigationPage(new MearPlayerView(song)));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user