fixed: crash from invalid buffer positioning, error from shutting thread

down before instantiation; removed old code;
This commit is contained in:
Harrison Deng 2018-08-29 22:32:44 -05:00
parent b84a3d6280
commit 97afc449b2
6 changed files with 18 additions and 26 deletions

View File

@ -33,12 +33,6 @@ public class MP3Metadata implements AudioMetadata {
try {
MP3File mp3file = (MP3File) AudioFileIO.read(fileHandle.file());
ID3v23Tag tag;
if (mp3file.hasID3v1Tag()) {
mp3file.setID3v2Tag(mp3file.getID3v1Tag());
mp3file.setID3v1Tag(null);
mp3file.commit();
tag = (ID3v23Tag) mp3file.getTagAndConvertOrCreateAndSetDefault();
}
tag = (ID3v23Tag) mp3file.getTagAndConvertOrCreateAndSetDefault();
@ -53,7 +47,7 @@ public class MP3Metadata implements AudioMetadata {
if (title.isEmpty()) {
title = fileHandle.nameWithoutExtension().replace('_', ' ');
}
} catch (IOException | CannotWriteException | CannotReadException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
} catch (IOException | CannotReadException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
Gdx.app.error("MP3Metadata", "Failed to read metadata of file: " + fileHandle.name());
}
}

View File

@ -28,7 +28,8 @@ public class DoubleHorizontalVisualizer implements Disposable {
private float barChangeRate = 6.5f;
private int smoothRange = 2;
private int binsToInclude = 120;
private Color color = new Color(0.5f, 0.6f, 0.8f, 0.46f);
private Color colorBegin = new Color(0.5f, 0.6f, 0.8f, 0.46f);
private Color colorEnd = new Color();
/**
*
* @param barCount amount of bars this visualizer should have.
@ -98,7 +99,6 @@ public class DoubleHorizontalVisualizer implements Disposable {
public void draw(Batch batch, float parentAlpha) {
batch.end();
Gdx.gl.glEnable(GL20.GL_BLEND);
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
@ -109,7 +109,7 @@ public class DoubleHorizontalVisualizer implements Disposable {
}
for (int bar = 0; bar < barCount; bar++) {
shapeRenderer.setColor(color);
shapeRenderer.setColor(colorBegin);
shapeRenderer.rect(offset + (spaceBetweenBars+barWidth)*bar, y+height, barWidth, barHeights[bar]);
shapeRenderer.rect(offset + (spaceBetweenBars+barWidth)*bar, y, barWidth, -barHeights[barHeights.length - 1 - bar]);
}

View File

@ -110,9 +110,9 @@ public class PCMObtainer implements Observer, PCMSystem {
private boolean synchronizeBufferWithPlayback() {
int bufferPos = calcBufferPosition();
if (bufferPos <= playingBuffer.limit()) {
if (bufferPos < playingBuffer.limit() || bufferPos >= 0) {
synchronized (this) {
playingBuffer.position(calcBufferPosition());
playingBuffer.position(bufferPos);
windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize);
return true;
}

View File

@ -7,6 +7,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
@ -121,6 +122,12 @@ public class MainPage extends Page implements Observer {
super.dispose();
}
@Override
public void setCameraPositionToPage(Vector3 cameraPosition) {
getStage().setScrollFocus(null);
super.setCameraPositionToPage(cameraPosition);
}
@Override
public void update(Observable o, Object arg) {
if (o == mc) {

View File

@ -49,7 +49,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
private Batch screenBatch;
private float targetDelta;
public MainScreen(RhythmBullet core) {
this.rhythmBullet = core;
stage = new Stage(new ScreenViewport());
@ -63,7 +62,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
listeners = new Listeners();
screenBatch = new SpriteBatch();
targetDelta = 1f/core.getScreenConfiguration().getTargetFramesPerSecond();
}
@Override
@ -80,7 +78,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
}
if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) {
stage.getCamera().position.lerp(cameraPosition, targetDelta*lerpAlpha);
stage.getCamera().position.lerp(cameraPosition, 0.15f);
stage.getViewport().apply();
}
@ -144,7 +142,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
calcLerpAlpha(Gdx.graphics.getWidth());
super.show();
}
@ -167,7 +164,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
stage.getViewport().update(width, height, false);
cameraPosition.x = width/2;
cameraPosition.y = height/2;
calcLerpAlpha(width);
super.resize(width, height);
}
@ -180,14 +176,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
super.dispose();
}
private void calcLerpAlpha(int width) {
if (width <= 3835) {
lerpAlpha = 5.0f;
} else {
lerpAlpha = 5.5f;
}
}
public void setDisplayedPage(Page page) {
page.setCameraPositionToPage(cameraPosition);
}

View File

@ -62,6 +62,7 @@ public class MusicSelectionPage extends Page implements Observer {
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer;
private float musicSelectDelay;
public MusicSelectionPage(AssetManager assetManager, Skin skin, MusicController musicController, AudioMetadataController musicMetadataController, ChangeListener backButtonListener, ChangeListener beginButtonListener) {
super(1, 0);
this.assets = assetManager;
@ -289,7 +290,9 @@ public class MusicSelectionPage extends Page implements Observer {
public void stop() {
clear();
thread.interrupt();
if (thread != null) {
thread.interrupt();
}
work = false;
}