# Streaming resources

No one resource should take so long to load that it keeps the screen from refreshing for a significant amount of time (if it does, then the resource should probably be streamed anyway :)).

So I altered my menu class as follows (this is just an example and I'm leaving out quite a bit):

public class MainMenu extends BasicGameState{
private Music[] theme = new Music[1];
public void init(GameContainer gameContainer, StateBasedGame stateBasedGame) throws SlickException{
InputStream[] musicStream = {ResourceLoader.getResourceAsStream("/path/to/theme1.ogg")}
try{
theme[0] = new Music(musicStream[0],"path/to/theme1.ogg");
}catch (Exception e){
e.printStackTrace;
}
}
(rest of class)


The music array is an array of org.newdawn.slick.Music

So I thought I'd done what would reduce loading time. However, when loading, it took just as long, but instead of showing a file as the current resource, it showed the stream.

I'd like to know how to do one or both of the following:

1. Stream a resource to reduce loading time as the wiki suggests.
2. Load only selected resources and load more when changing states (load the game music only when entering game state, etc.).

public void init(GameContainer gc, StateBasedGame game) throws SlickException{

Adding true after the file reference indicates that you want to stream the audio.