mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-06 06:53:59 +00:00
format/reindent
using phero resources defaults to a file now
This commit is contained in:
parent
851e5f2c08
commit
571a2fe348
6 changed files with 408 additions and 485 deletions
|
|
@ -31,12 +31,8 @@
|
|||
*/
|
||||
package org.lwjgl.test.fmod3;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.lwjgl.fmod3.FMOD;
|
||||
import org.lwjgl.fmod3.FMODException;
|
||||
|
|
@ -51,104 +47,59 @@ import org.lwjgl.fmod3.FSound;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public class MusicPlayer {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
if(args.length < 1) {
|
||||
System.out.println("Usage:\n MusicPlayer <file>");
|
||||
return;
|
||||
}
|
||||
|
||||
File file = new File(args[0]);
|
||||
if (!file.exists()) {
|
||||
System.out.println("No such file: " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
FMOD.create();
|
||||
} catch (FMODException fmode) {
|
||||
fmode.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Initializing FMOD");
|
||||
if(!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Loading " + args[0]);
|
||||
|
||||
// choose either way of loading...
|
||||
|
||||
// using name (path)
|
||||
FMusicModule module = FMusic.FMUSIC_LoadSong(args[0]);
|
||||
|
||||
// using name (path), extended mode
|
||||
//FMusicModule module = FMusic.FMUSIC_LoadSongEx(args[0], 0, 0, 0, null);
|
||||
|
||||
// using memory buffers
|
||||
//ByteBuffer data = getData(args[0]);
|
||||
//FMusicModule module = FMusic.FMUSIC_LoadSongEx(data, 0, data.remaining(), FSound.FSOUND_LOADMEMORY, null);
|
||||
|
||||
if(module != null) {
|
||||
System.out.println("Loaded. Playing module of type: " + FMusic.FMUSIC_GetType(module));
|
||||
FMusic.FMUSIC_PlaySong(module);
|
||||
|
||||
System.out.println("Press enter to stop playing");
|
||||
try {
|
||||
System.in.read();
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
FMusic.FMUSIC_StopSong(module);
|
||||
|
||||
System.out.println("Done playing. Cleaning up");
|
||||
FMusic.FMUSIC_FreeSong(module);
|
||||
} else {
|
||||
System.out.println("Unable to play: " + args[0]);
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
}
|
||||
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
if (args.length < 1) {
|
||||
System.out.println("Usage:\n MusicPlayer <file>");
|
||||
|
||||
// default to Missing_you.mod
|
||||
args = new String[] { "res\\Missing_you.mod"};
|
||||
System.out.println("Using default: " + args[0]);
|
||||
}
|
||||
|
||||
File file = new File(args[0]);
|
||||
if (!file.exists()) {
|
||||
System.out.println("No such file: " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
FMOD.create();
|
||||
} catch (FMODException fmode) {
|
||||
fmode.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Initializing FMOD");
|
||||
if (!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Loading " + args[0]);
|
||||
|
||||
// using name (path)
|
||||
FMusicModule module = FMusic.FMUSIC_LoadSong(args[0]);
|
||||
|
||||
if (module != null) {
|
||||
System.out.println("Loaded. Playing module of type: " + FMusic.FMUSIC_GetType(module));
|
||||
FMusic.FMUSIC_PlaySong(module);
|
||||
|
||||
System.out.println("Press enter to stop playing");
|
||||
try {
|
||||
System.in.read();
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
FMusic.FMUSIC_StopSong(module);
|
||||
|
||||
System.out.println("Done playing. Cleaning up");
|
||||
FMusic.FMUSIC_FreeSong(module);
|
||||
} else {
|
||||
System.out.println("Unable to play: " + args[0]);
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
}
|
||||
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the file into a ByteBuffer
|
||||
*
|
||||
* @param filename
|
||||
* Name of file to load
|
||||
* @return ByteBuffer containing file data
|
||||
*/
|
||||
static protected ByteBuffer getData(String filename) {
|
||||
ByteBuffer buffer = null;
|
||||
|
||||
System.out.println("Attempting to load: " + filename);
|
||||
|
||||
try {
|
||||
BufferedInputStream bis = new BufferedInputStream(StreamPlayer.class.getClassLoader().getResourceAsStream(filename));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
int bufferLength = 4096;
|
||||
byte[] readBuffer = new byte[bufferLength];
|
||||
int read = -1;
|
||||
|
||||
while ((read = bis.read(readBuffer, 0, bufferLength)) != -1) {
|
||||
baos.write(readBuffer, 0, read);
|
||||
}
|
||||
|
||||
//done reading, close
|
||||
bis.close();
|
||||
|
||||
// if ogg vorbis data, we need to pass it unmodified to alBufferData
|
||||
buffer = ByteBuffer.allocateDirect(baos.size());
|
||||
buffer.order(ByteOrder.nativeOrder());
|
||||
buffer.put(baos.toByteArray());
|
||||
buffer.flip();
|
||||
System.out.println("loaded " + buffer.remaining() + " bytes");
|
||||
} catch (Exception ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue