public void load_from_file(string path)
{
string newPath = System.IO.Path.Combine(Environment.CurrentDirectory, path);
try
{
MessageBox.Show(newPath);
// Read the JSON file
string jsonContent = File.ReadAllText(@newPath);
// Deserialize the JSON content into a Person object using Newtonsoft.Json
Song currentSong = JsonConvert.DeserializeObject<Song>(jsonContent);
if (currentSong != null)
{
// Display the properties in the TextBox
id = currentSong.id;
title = currentSong.title;
artist = currentSong.artist;
bpm = currentSong.bpm;
duration = currentSong.duration;
audioPath = currentSong.audioPath;
beatCount = currentSong.beatCount;
string newAudioPath = System.IO.Path.Combine(Environment.CurrentDirectory, audioPath);
waveSource = CodecFactory.Instance.GetCodec(newAudioPath);
soundOut = new WasapiOut() { Latency = 100 };
soundOut.Initialize(waveSource);
}
else
{
MessageBox.Show("Error: Could not deserialize the JSON.");
}
}
catch (JsonException ex)
{
MessageBox.Show($"Invalid JSON format. Error: {ex.Message}");
}
catch (Exception ex)
{
MessageBox.Show($"Error: {ex.Message}");
}
}
public void load_from_file(string path)
{
string newPath = System.IO.Path.Combine(Environment.CurrentDirectory, path);
try
{
MessageBox.Show(newPath);
// Read the JSON file
string jsonContent = File.ReadAllText(@newPath);
// Deserialize the JSON content into a Person object using Newtonsoft.Json
Song currentSong = JsonConvert.DeserializeObject<Song>(jsonContent);
if (currentSong != null)
{
// Display the properties in the TextBox
id = currentSong.id;
title = currentSong.title;
artist = currentSong.artist;
bpm = currentSong.bpm;
duration = currentSong.duration;
audioPath = currentSong.audioPath;
beatCount = currentSong.beatCount;
string newAudioPath = System.IO.Path.Combine(Environment.CurrentDirectory, audioPath);
waveSource = CodecFactory.Instance.GetCodec(newAudioPath);
soundOut = new WasapiOut() { Latency = 100 };
soundOut.Initialize(waveSource);
}
else
{
MessageBox.Show("Error: Could not deserialize the JSON.");
}
}
catch (JsonException ex)
{
MessageBox.Show($"Invalid JSON format. Error: {ex.Message}");
}
catch (Exception ex)
{
MessageBox.Show($"Error: {ex.Message}");
}
}