Fix deserialization of notes from rhys file

This commit is contained in:
Thastertyn 2024-06-11 13:17:29 +02:00
parent 024b5aef75
commit 079c01b01c
3 changed files with 5 additions and 8 deletions

View File

@ -5,6 +5,7 @@ using UnityEngine;
namespace BangerTypes namespace BangerTypes
{ {
[Serializable]
public class Note public class Note
{ {
public float t; // Time public float t; // Time

View File

@ -5,6 +5,7 @@ using UnityEngine;
namespace BangerTypes namespace BangerTypes
{ {
[Serializable]
public class Rhys public class Rhys
{ {
public Note[] notes; public Note[] notes;

View File

@ -32,7 +32,7 @@ namespace MenuAndSongs
Rhys rhys = JsonUtility.FromJson<Rhys>(jsonContent); Rhys rhys = JsonUtility.FromJson<Rhys>(jsonContent);
string title = "<b>" + (rhys.title ?? "Title not found") + "</b>"; string title = "<b>" + (rhys.title ?? "Title not found") + "</b>";
string artist = String.IsNullOrEmpty(rhys.artist) ? "Artist not found" : "By: <b>" + rhys.artist + "</b>"; string artist = string.IsNullOrEmpty(rhys.artist) ? "Artist not found" : "By: <b>" + rhys.artist + "</b>";
string album = "Album information not available"; string album = "Album information not available";
TimeSpan duration = TimeSpan.FromSeconds(rhys.track_time); TimeSpan duration = TimeSpan.FromSeconds(rhys.track_time);
@ -55,10 +55,8 @@ namespace MenuAndSongs
} }
var notes = rhys.notes; var notes = rhys.notes;
Debug.Log("NOTES: ");
Debug.Log(notes);
return new() return new Song
{ {
Title = title, Title = title,
Artist = artist, Artist = artist,
@ -66,23 +64,20 @@ namespace MenuAndSongs
DurationSpan = duration, DurationSpan = duration,
Duration = formattedTimeSpan, Duration = formattedTimeSpan,
CoverArt = coverImage, CoverArt = coverImage,
Notes = notes,
Clip = LoadAudioFromBase64(rhys.audio) Clip = LoadAudioFromBase64(rhys.audio)
}; };
} }
private static AudioClip LoadAudioFromBase64(string base64String) private static AudioClip LoadAudioFromBase64(string base64String)
{ {
// Decode Base64 String to byte array
byte[] mp3Bytes = Convert.FromBase64String(base64String); byte[] mp3Bytes = Convert.FromBase64String(base64String);
// Create a temporary file path
string tempFilePath = Path.Combine(Application.persistentDataPath, "tempMp3File.mp3"); string tempFilePath = Path.Combine(Application.persistentDataPath, "tempMp3File.mp3");
System.IO.File.WriteAllBytes(tempFilePath, mp3Bytes); System.IO.File.WriteAllBytes(tempFilePath, mp3Bytes);
// Load the AudioClip synchronously
AudioClip clip = LoadAudioSync(tempFilePath); AudioClip clip = LoadAudioSync(tempFilePath);
// Optionally delete the temporary file if no longer needed
System.IO.File.Delete(tempFilePath); System.IO.File.Delete(tempFilePath);
return clip; return clip;