Working through issue where Song does not start playing until a certain point. This is an issue because when retrieving the repeat mode status from the player it defaults to off even though it is initialized from the database.
This commit is contained in:
@@ -25,6 +25,7 @@ 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)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ using System.Text;
|
|||||||
|
|
||||||
using SQLite;
|
using SQLite;
|
||||||
|
|
||||||
|
using Mear.Models.PlayerControls;
|
||||||
|
|
||||||
namespace Mear.Models
|
namespace Mear.Models
|
||||||
{
|
{
|
||||||
[DataContract]
|
[DataContract]
|
||||||
@@ -14,6 +16,6 @@ namespace Mear.Models
|
|||||||
[PrimaryKey, Column("Id"), AutoIncrement]
|
[PrimaryKey, Column("Id"), AutoIncrement]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public bool ShuffleOn { get; set; } = false;
|
public bool ShuffleOn { get; set; } = false;
|
||||||
public bool RepeatOn { get; set; } = false;
|
public int RepeatOn { get; set; } = (int)PlayerControls.Repeat.OFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Mear.Models.PlayerControls
|
||||||
|
{
|
||||||
|
public enum Repeat
|
||||||
|
{
|
||||||
|
OFF = 0,
|
||||||
|
ONE,
|
||||||
|
ALL
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,9 @@ using Mear.Constants;
|
|||||||
using Mear.Constants.API;
|
using Mear.Constants.API;
|
||||||
using Mear.Models;
|
using Mear.Models;
|
||||||
using Mear.Models.Authentication;
|
using Mear.Models.Authentication;
|
||||||
|
using Mear.Models.PlayerControls;
|
||||||
using Mear.Repositories.Database;
|
using Mear.Repositories.Database;
|
||||||
|
using Mear.Utilities;
|
||||||
|
|
||||||
namespace Mear.Playback
|
namespace Mear.Playback
|
||||||
{
|
{
|
||||||
@@ -85,11 +87,13 @@ namespace Mear.Playback
|
|||||||
}
|
}
|
||||||
public static async Task<Song> ControlMusic(Song song, PlayControls control)
|
public static async Task<Song> ControlMusic(Song song, PlayControls control)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (control)
|
switch (control)
|
||||||
{
|
{
|
||||||
case PlayControls.PLAYOFFLINE:
|
case PlayControls.PLAYOFFLINE:
|
||||||
var songPath = song.SongPath;
|
var songPath = song.SongPath;
|
||||||
await CrossMediaManager.Current.Play(songPath);
|
await CrossMediaManager.Current.Play(songPath);
|
||||||
|
InitializeRepeatMode();
|
||||||
break;
|
break;
|
||||||
case PlayControls.PAUSE:
|
case PlayControls.PAUSE:
|
||||||
await CrossMediaManager.Current.Pause();
|
await CrossMediaManager.Current.Pause();
|
||||||
@@ -98,12 +102,11 @@ namespace Mear.Playback
|
|||||||
await CrossMediaManager.Current.Play();
|
await CrossMediaManager.Current.Play();
|
||||||
break;
|
break;
|
||||||
case PlayControls.STREAM:
|
case PlayControls.STREAM:
|
||||||
return StreamSong(song);
|
song = StreamSong(song);
|
||||||
break;
|
InitializeRepeatMode();
|
||||||
|
return song;
|
||||||
case PlayControls.REPEAT:
|
case PlayControls.REPEAT:
|
||||||
// TODO: Not fully implemented
|
ToggleRepeat();
|
||||||
CrossMediaManager.Current.ToggleRepeat();
|
|
||||||
var i = CrossMediaManager.Current.RepeatMode;
|
|
||||||
break;
|
break;
|
||||||
case PlayControls.SHUFFLE:
|
case PlayControls.SHUFFLE:
|
||||||
// TODO: Implement shuffling
|
// TODO: Implement shuffling
|
||||||
@@ -119,6 +122,23 @@ namespace Mear.Playback
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string RetrieveRepeatString()
|
||||||
|
{
|
||||||
|
var ctrlRepeatMode = CrossMediaManager.Current.RepeatMode;
|
||||||
|
|
||||||
|
switch (ctrlRepeatMode)
|
||||||
|
{
|
||||||
|
case MediaManager.Playback.RepeatMode.Off:
|
||||||
|
return "RepOff";
|
||||||
|
case MediaManager.Playback.RepeatMode.One:
|
||||||
|
return "RepOn";
|
||||||
|
case MediaManager.Playback.RepeatMode.All:
|
||||||
|
return "RepAll";
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
private static Song StreamSong(Song song)
|
private static Song StreamSong(Song song)
|
||||||
{
|
{
|
||||||
string tmpFile = Path.GetTempPath() + "track.mp3";
|
string tmpFile = Path.GetTempPath() + "track.mp3";
|
||||||
@@ -145,7 +165,8 @@ namespace Mear.Playback
|
|||||||
|
|
||||||
var response = client.DownloadData(request);
|
var response = client.DownloadData(request);
|
||||||
|
|
||||||
CrossMediaManager.Current.Play(tmpFile);
|
PlaySong(tmpFile);
|
||||||
|
|
||||||
song.SongPath = tmpFile;
|
song.SongPath = tmpFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +179,36 @@ namespace Mear.Playback
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void InitializeModes()
|
||||||
|
{
|
||||||
|
InitializeRepeatMode();
|
||||||
|
}
|
||||||
|
private static void InitializeRepeatMode()
|
||||||
|
{
|
||||||
|
var ctrlRepo = new DBMusicControlsRepository();
|
||||||
|
var repeatMode = ctrlRepo.IsRepeatOn();
|
||||||
|
|
||||||
|
var mode = RepeatUtility.RetrieveRepeatMode(repeatMode);
|
||||||
|
|
||||||
|
CrossMediaManager.Current.RepeatMode = mode;
|
||||||
|
}
|
||||||
|
private static async Task PlaySong(string songPath)
|
||||||
|
{
|
||||||
|
await CrossMediaManager.Current.Play(songPath);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using Mear.Models;
|
using Mear.Models;
|
||||||
|
using Mear.Models.PlayerControls;
|
||||||
|
using Mear.Utilities;
|
||||||
|
|
||||||
namespace Mear.Repositories.Database
|
namespace Mear.Repositories.Database
|
||||||
{
|
{
|
||||||
@@ -48,18 +50,15 @@ namespace Mear.Repositories.Database
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public bool IsRepeatOn()
|
public Repeat IsRepeatOn()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (DoesTableExist("MusicControls"))
|
if (DoesTableExist("MusicControls"))
|
||||||
{
|
{
|
||||||
bool? repeat = _Db.Table<MusicControls>().First().RepeatOn;
|
var repeat = _Db.Table<MusicControls>().First().RepeatOn;
|
||||||
|
|
||||||
if (repeat != null)
|
return (Repeat)repeat;
|
||||||
{
|
|
||||||
return repeat.Value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -67,7 +66,7 @@ namespace Mear.Repositories.Database
|
|||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return Repeat.OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateRepeat()
|
public void UpdateRepeat()
|
||||||
@@ -77,7 +76,9 @@ namespace Mear.Repositories.Database
|
|||||||
if (DoesTableExist("MusicControls"))
|
if (DoesTableExist("MusicControls"))
|
||||||
{
|
{
|
||||||
var control = RetrieveMusicControls();
|
var control = RetrieveMusicControls();
|
||||||
control.RepeatOn = !control.RepeatOn;
|
var repeatMode = (Repeat)control.RepeatOn;
|
||||||
|
control.RepeatOn = RepeatUtility.ToggleRepeatMode(repeatMode);
|
||||||
|
|
||||||
_Db.Update(control);
|
_Db.Update(control);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using MediaManager;
|
||||||
|
|
||||||
|
using Mear.Models.PlayerControls;
|
||||||
|
|
||||||
|
namespace Mear.Utilities
|
||||||
|
{
|
||||||
|
public class RepeatUtility
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
public static MediaManager.Playback.RepeatMode RetrieveRepeatMode(Repeat repeatMode)
|
||||||
|
{
|
||||||
|
switch (repeatMode)
|
||||||
|
{
|
||||||
|
case Repeat.OFF:
|
||||||
|
return MediaManager.Playback.RepeatMode.Off;
|
||||||
|
case Repeat.ONE:
|
||||||
|
return MediaManager.Playback.RepeatMode.One;
|
||||||
|
case Repeat.ALL:
|
||||||
|
return MediaManager.Playback.RepeatMode.All;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MediaManager.Playback.RepeatMode.Off;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string RepeatString(Repeat repeatMode)
|
||||||
|
{
|
||||||
|
switch (repeatMode)
|
||||||
|
{
|
||||||
|
case Repeat.OFF:
|
||||||
|
return "RepOff";
|
||||||
|
case Repeat.ONE:
|
||||||
|
return "RepOne";
|
||||||
|
case Repeat.ALL:
|
||||||
|
return "RepAll";
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
public static string ToggleRepeatString(Repeat repeatMode)
|
||||||
|
{
|
||||||
|
switch (repeatMode)
|
||||||
|
{
|
||||||
|
case Repeat.OFF:
|
||||||
|
return "RepOn";
|
||||||
|
case Repeat.ONE:
|
||||||
|
return "RepAll";
|
||||||
|
case Repeat.ALL:
|
||||||
|
return "RepOff";
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int ToggleRepeatMode(Repeat repeatMode)
|
||||||
|
{
|
||||||
|
switch (repeatMode)
|
||||||
|
{
|
||||||
|
case Repeat.OFF:
|
||||||
|
return (int)Repeat.ONE;
|
||||||
|
case Repeat.ONE:
|
||||||
|
return (int)Repeat.ALL;
|
||||||
|
case Repeat.ALL:
|
||||||
|
return (int)Repeat.OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,12 +12,15 @@ using Xamarin.Forms.Xaml;
|
|||||||
|
|
||||||
using Mear.Constants;
|
using Mear.Constants;
|
||||||
using Mear.Models;
|
using Mear.Models;
|
||||||
|
using Mear.Models.PlayerControls;
|
||||||
using Mear.Playback;
|
using Mear.Playback;
|
||||||
using Mear.Repositories.Database;
|
using Mear.Repositories.Database;
|
||||||
using Mear.Repositories.Remote;
|
using Mear.Repositories.Remote;
|
||||||
using Mear.Utilities;
|
using Mear.Utilities;
|
||||||
using Mear.ViewModels;
|
using Mear.ViewModels;
|
||||||
|
|
||||||
|
using RepeatMode = Mear.Models.PlayerControls.Repeat;
|
||||||
|
|
||||||
namespace Mear.Views
|
namespace Mear.Views
|
||||||
{
|
{
|
||||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||||
@@ -98,10 +101,10 @@ namespace Mear.Views
|
|||||||
|
|
||||||
var controlRepo = new DBMusicControlsRepository();
|
var controlRepo = new DBMusicControlsRepository();
|
||||||
var shuffleOn = controlRepo.IsShuffleOn();
|
var shuffleOn = controlRepo.IsShuffleOn();
|
||||||
var repeatOn = controlRepo.IsRepeatOn();
|
var repeatMode = (RepeatMode)controlRepo.IsRepeatOn();
|
||||||
|
|
||||||
Shuffle.Text = (shuffleOn) ? "ShfOn" : "ShfOff";
|
Shuffle.Text = (shuffleOn) ? "ShfOn" : "ShfOff";
|
||||||
Repeat.Text = (repeatOn) ? "RepOn" : "RepOff";
|
Repeat.Text = MearPlayer.RetrieveRepeatString();
|
||||||
|
|
||||||
EndTime.Text = endTime;
|
EndTime.Text = endTime;
|
||||||
}
|
}
|
||||||
@@ -185,13 +188,12 @@ namespace Mear.Views
|
|||||||
}
|
}
|
||||||
private void Repeat_Clicked(object sender, EventArgs e)
|
private void Repeat_Clicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var musicCtrl = new DBMusicControlsRepository();
|
Task.Run(async () =>
|
||||||
var control = musicCtrl.IsRepeatOn();
|
{
|
||||||
Repeat.Text = (!control) ? "RepOn" : "RepOff";
|
await MearPlayer.ControlMusic(_song, PlayControls.REPEAT);
|
||||||
|
}).Wait();
|
||||||
|
|
||||||
musicCtrl.UpdateRepeat();
|
Repeat.Text = MearPlayer.RetrieveRepeatString();
|
||||||
|
|
||||||
MearPlayer.ControlMusic(_song, PlayControls.REPEAT);
|
|
||||||
}
|
}
|
||||||
private void Shuffle_Clicked(object sender, EventArgs e)
|
private void Shuffle_Clicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user