Fix deserialization of notes from rhys file
This commit is contained in:
parent
024b5aef75
commit
079c01b01c
@ -5,6 +5,7 @@ using UnityEngine;
|
||||
|
||||
namespace BangerTypes
|
||||
{
|
||||
[Serializable]
|
||||
public class Note
|
||||
{
|
||||
public float t; // Time
|
||||
|
@ -5,6 +5,7 @@ using UnityEngine;
|
||||
|
||||
namespace BangerTypes
|
||||
{
|
||||
[Serializable]
|
||||
public class Rhys
|
||||
{
|
||||
public Note[] notes;
|
||||
|
@ -32,7 +32,7 @@ namespace MenuAndSongs
|
||||
Rhys rhys = JsonUtility.FromJson<Rhys>(jsonContent);
|
||||
|
||||
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";
|
||||
|
||||
TimeSpan duration = TimeSpan.FromSeconds(rhys.track_time);
|
||||
@ -55,10 +55,8 @@ namespace MenuAndSongs
|
||||
}
|
||||
|
||||
var notes = rhys.notes;
|
||||
Debug.Log("NOTES: ");
|
||||
Debug.Log(notes);
|
||||
|
||||
return new()
|
||||
return new Song
|
||||
{
|
||||
Title = title,
|
||||
Artist = artist,
|
||||
@ -66,23 +64,20 @@ namespace MenuAndSongs
|
||||
DurationSpan = duration,
|
||||
Duration = formattedTimeSpan,
|
||||
CoverArt = coverImage,
|
||||
Notes = notes,
|
||||
Clip = LoadAudioFromBase64(rhys.audio)
|
||||
};
|
||||
}
|
||||
|
||||
private static AudioClip LoadAudioFromBase64(string base64String)
|
||||
{
|
||||
// Decode Base64 String to byte array
|
||||
byte[] mp3Bytes = Convert.FromBase64String(base64String);
|
||||
|
||||
// Create a temporary file path
|
||||
string tempFilePath = Path.Combine(Application.persistentDataPath, "tempMp3File.mp3");
|
||||
System.IO.File.WriteAllBytes(tempFilePath, mp3Bytes);
|
||||
|
||||
// Load the AudioClip synchronously
|
||||
AudioClip clip = LoadAudioSync(tempFilePath);
|
||||
|
||||
// Optionally delete the temporary file if no longer needed
|
||||
System.IO.File.Delete(tempFilePath);
|
||||
|
||||
return clip;
|
||||
|
Loading…
x
Reference in New Issue
Block a user