Implement PlayerConfig building

develop
LEdoian 3 years ago
parent ec2ab8f619
commit eb7d1dda65

@ -100,23 +100,27 @@ namespace QuickPlay
/// </summary>
public class PlayerConfiguration
{
List<IPlayable> songs;
Dictionary<string, IPlayable> songs;
string playerName;
public static PlayerConfiguration FromFile(StreamReader reader)
{
var parser = new IniParser(reader);
var ini = parser.Parse();
foreach (string key in ini.Keys)
var result = new PlayerConfiguration();
foreach (var elem in ini)
{
// Two options: either general options, or song descriptions
if (key == "general")
if (elem.Key == "general")
{
result.playerName = elem.Value["name"];
} else
{
// Song
var song = new Song(elem.Key, elem.Value);
result.songs[elem.Key] = song;
}
}
return result;
}
public IPlayer GetPlayer()
@ -168,4 +172,21 @@ namespace QuickPlay
{
public PlayerConfiguration GetConfiguration() => null;
}
class Song: IPlayable
{
public string Identifier { get; private set; }
public PlayableMetadata Metadata { get; private set; }
public Song(string id, Dictionary<string, string> data) {
Identifier = id;
Metadata = new PlayableMetadata
{
usualPlayingTime = TimeSpan.Parse(data["time"])
};
}
public void Play()
{
throw new NotImplementedException();
}
}
}

@ -11,6 +11,7 @@ namespace QuickPlay
/// </summary>
public interface IPlayer
{
Dictionary<string, IPlayable> Songs { get; }
void Play(string identifier);
float CurrentProgress { get; }
bool IsReady { get; }
@ -21,12 +22,15 @@ namespace QuickPlay
/// </summary>
// This is not really an interface, but since it is a dataclass, I treat it
// more as a part of interface, so it belongs to this file.
class PlayableMetadata
// Also, in order not to need boilerplate code, this should be semantically
// treated as immutable even though it's not.
public class PlayableMetadata
{
public readonly TimeSpan usualPlayingTime;
public TimeSpan usualPlayingTime;
}
interface IPlayable
public interface IPlayable
{
void Play();
string Identifier { get; }

Loading…
Cancel
Save