In my scenario, there is a title screen world that plays sound when it is initialized, and has a button to go to a cutscene world. Both are subclasses of the foodtruck class. The cutscene world stops the sound then runs an ask prompt for the player's username. Whenever I run the scenario, input something in the prompt, and reset to enter the title world again, the sound there becomes really glitchy and gives me a weird error:
Foodtruck class:
Title class:
cutscene class:
The error doesn't happen if I don't input something in the prompt beforehand, so I think it has something to do with that. Any help would be really appreciated!!
Exception in thread "SoundStream:file:/C:/Users/John%20Doe/OneDrive/Summative/sounds/foodtrucktitle.mp3" java.lang.IndexOutOfBoundsException at java.base/java.io.PushbackInputStream.read(PushbackInputStream.java:166) at javazoom.jl.decoder.Bitstream.readBytes(Bitstream.java:639) at javazoom.jl.decoder.Bitstream.syncHeader(Bitstream.java:428) at javazoom.jl.decoder.Header.read_header(Header.java:122) at javazoom.jl.decoder.Bitstream.nextFrame(Bitstream.java:328) at javazoom.jl.decoder.Bitstream.readNextFrame(Bitstream.java:315) at javazoom.jl.decoder.Bitstream.readFrame(Bitstream.java:286) at greenfoot.sound.Mp3AudioInputStream.read(Mp3AudioInputStream.java:221) at greenfoot.sound.SoundStream.run(SoundStream.java:303) at java.base/java.lang.Thread.run(Thread.java:833)
public class FoodTruck extends World
{
private static String question; //stores player name
boolean isAsked; //name ask condition
SimpleTimer timer = new SimpleTimer(); //timer object
boolean timerRunning; // timer start condition
private static int day; //game days
static GreenfootSound title = new GreenfootSound("foodtrucktitle.mp3");
static GreenfootSound daystart = new GreenfootSound("daystart.mp3");
static GreenfootSound order = new GreenfootSound("truckorder.mp3");
}public class FoodTruckStart extends FoodTruck
{
/**
* Constructor for objects of class FoodTruckStart.
*
*/
public FoodTruckStart()
{
addObject(new FoodTruckPlay(), 100, 200);
addObject(new FoodTruckSet(), 200, 200);
addObject(new back(), 300, 200);
title.playLoop();
}
}public class FoodTruckCutscene extends FoodTruck
{
/**
* Constructor for objects of class FoodTruckCutscene.
*
*/
public FoodTruckCutscene()
{
addObject(new skipcutscene(), 550, 350);
}
public void act()
{
title.stop();
if (!isAsked)
{
setQuestion(Greenfoot.ask("Enter your name:"));
isAsked = true;
}
if (isAsked)
{
if (!timerRunning)
{
timer.mark();
timerRunning = true;
}
if (timerRunning && timer.millisElapsed() > 1000 && timer.millisElapsed() < 4000)
{
setBackground("concept1.png");
//cutscene sequence. will do later
}
else if (timerRunning && timer.millisElapsed() > 4000)
{
Greenfoot.setWorld(new FoodTruckDay());
}
}
}
}

