- Home /
[SOLVED] Cannot create FMOD: Sound instance for resource End of file unexpectedly reached while trying to read essential data,Cannot Create FMOD Sound Instance For Resource
I am working on a beat game, and want the player to set their own file path using an Input Field, so that they can use any song they want. Unfortunately, when I have the file path entered in the input field, then click my main menu's play button, it sends me to my game scene. Then I get this error:
Error: Cannot create FMOD::Sound instance for resource 0x0000012DBD454B10: file:///ang/Desktop/Rise.ogg, (End of file unexpectedly reached while trying to read essential data (truncated data?). )
UnityEngine.WWW:GetAudioClip(Boolean, Boolean, AudioType)
<LoadAudio>d__4:MoveNext() (at Assets/loadwww.cs:32)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
This is my code that is giving me issues. The print is to confirm that the string has received the text of the input field.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class loadwww : MonoBehaviour {
public string testPathString = SongPath.FilePath.text.ToString();
public void Start()
{
print(testPathString);
StartCoroutine(LoadAudio());
}
public void Update()
{
if (Time.timeScale == 0.0f)
{
audioContainer.Stop();
}
}
public AudioSource audioContainer;
IEnumerator LoadAudio()
{
FullPath = "file:///" + testPathString;
WWW URL = new WWW(FullPath);
yield return URL;
audioContainer.clip = URL.GetAudioClip(false, true, AudioType.OGGVORBIS);
}
public void startButtonClicked()
{
audioContainer.Play();
}
}
, Error: Cannot create FMOD::Sound instance for resource 0x0000012DBD454B10: file:///ang/Desktop/Rise.ogg, (End of file unexpectedly reached while trying to read essential data (truncated data?). ) UnityEngine.WWW:GetAudioClip(Boolean, Boolean, AudioType) d__4:MoveNext() (at Assets/loadwww.cs:32) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
That is the error that I am getting. I want the player to be able to use an input field to set the path so, I have a string that accesses the Input Field text, and when I put that as the full path, I get that error. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class loadwww : MonoBehaviour {
public string testPathString = SongPath.FilePath.text.ToString();
public void Start()
{
print(testPathString);
StartCoroutine(LoadAudio());
}
public void Update()
{
if (Time.timeScale == 0.0f)
{
audioContainer.Stop();
}
}
public AudioSource audioContainer;
IEnumerator LoadAudio()
{
string FullPath = "file:///" + testPathString;
WWW URL = new WWW(FullPath);
yield return URL;
audioContainer.clip = URL.GetAudioClip(false, true, AudioType.OGGVORBIS);
}
public void startButtonClicked()
{
audioContainer.Play();
}
}
The print statement confirms that the string did successfully get the input field's text, and it looks exactly like if I inserted the file path into the code. Any ideas why it is giving me this error, and how do I fix it? Thanks in advance!
Answer by scottmakesgames_unity · Jan 25, 2020 at 07:13 PM
Solved: I looked at the print again [the one that confirms it receives the input field text] and found that the text I entered was cut off. Apparently, the text only saves what is visible, and as such whenever you need to press the left arrow to show previous text in the input field, the full text will not be saved. Only the visible part. Very simple fix to this: Extend the length of the input field, to allow it to display more, and it will save all.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Localhost WWW proxy issue (can't bypass?) 1 Answer
WWW login button doesn't have name or id 0 Answers
no extension method `LoadAssetAsync' of type `UnityEngine.AssetBundle 0 Answers