began map implementing
This commit is contained in:
@@ -49,8 +49,14 @@ public interface AudioData extends Disposable {
|
||||
public AudioFormat getFormat();
|
||||
|
||||
/**
|
||||
* Returns object containing basic audio data;
|
||||
* returns sample count
|
||||
* @return
|
||||
*/
|
||||
public int getSampleCount();
|
||||
|
||||
/**
|
||||
* returns duration of song in seconds
|
||||
* @return
|
||||
*/
|
||||
public float getDuration();
|
||||
}
|
||||
|
21
core/src/zero1hd/polyjet/audio/GamePlayMap.java
Executable file
21
core/src/zero1hd/polyjet/audio/GamePlayMap.java
Executable file
@@ -0,0 +1,21 @@
|
||||
package zero1hd.polyjet.audio;
|
||||
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
|
||||
public class GamePlayMap {
|
||||
private Music playableClip;
|
||||
private float playTime;
|
||||
|
||||
public GamePlayMap(AudioData audioData) {
|
||||
playableClip = audioData.getPlaybackMusic();
|
||||
playTime = audioData.getDuration();
|
||||
}
|
||||
|
||||
public Music getPlayableClip() {
|
||||
return playableClip;
|
||||
}
|
||||
|
||||
public float getPlayTime() {
|
||||
return playTime;
|
||||
}
|
||||
}
|
@@ -31,13 +31,17 @@ public class Mp3AudioData implements AudioData {
|
||||
private int readIndex;
|
||||
|
||||
private int sampleCount;
|
||||
|
||||
private float durationInSeconds;
|
||||
|
||||
private AudioInputStream in;
|
||||
|
||||
Decoder decoder = new Decoder();
|
||||
public Mp3AudioData(FileHandle audioFile) {
|
||||
try {
|
||||
sampleCount = (int) new MP3File(audioFile.file()).getMP3AudioHeader().getNumberOfFrames();
|
||||
MP3File mp3File = new MP3File(audioFile.file());
|
||||
|
||||
sampleCount = (int) mp3File.getMP3AudioHeader().getNumberOfFrames();
|
||||
durationInSeconds = mp3File.getMP3AudioHeader().getNumberOfFrames()/readWindowSize;
|
||||
} catch (IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@@ -149,4 +153,9 @@ public class Mp3AudioData implements AudioData {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDuration() {
|
||||
return durationInSeconds;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -80,4 +80,9 @@ public class WavAudioData implements AudioData {
|
||||
playbackMusic.dispose();
|
||||
decoder.cleanAndClose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDuration() {
|
||||
return decoder.getDurationInSeconds();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user