improved metadata analysis, added persij as library, added refresh to gui interface

This commit is contained in:
Raybz@Raybz 2013-06-28 08:57:30 +02:00
parent d37263b4bf
commit 4513c6b6bb
26 changed files with 223 additions and 664 deletions

Binary file not shown.

Binary file not shown.

View File

@ -32,18 +32,19 @@ dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.AudioProcessing-1.0.jar=lib\\AudioProcessing-1.0.jar
file.reference.BaseIO-1.0.jar=lib/BaseIO-1.0.jar
file.reference.commons-codec-1.4.jar=lib\\commons-codec-1.4.jar
file.reference.commons-io-2.1.jar=lib\\commons-io-2.1.jar
file.reference.commons-lang3-3.1.jar=lib\\commons-lang3-3.1.jar
file.reference.commons-logging-1.1.1.jar=lib\\commons-logging-1.1.1.jar
file.reference.httpclient-4.1.3.jar=lib\\httpclient-4.1.3.jar
file.reference.httpcore-4.1.4.jar=lib\\httpcore-4.1.4.jar
file.reference.jaudiotagger-2.2.0.jar=lib\\jaudiotagger-2.2.0.jar
file.reference.jl1.0.1.jar=lib\\jl1.0.1.jar
file.reference.jna-3.5.2.jar=lib\\jna-3.5.2.jar
file.reference.jogg-0.0.7.jar=lib\\jogg-0.0.7.jar
file.reference.jorbis-0.0.15.jar=lib\\jorbis-0.0.15.jar
file.reference.mp3spi1.9.5.jar=lib\\mp3spi1.9.5.jar
file.reference.PersiJ-1.0.jar=lib/PersiJ-1.0.jar
file.reference.platform-3.5.2.jar=lib\\platform-3.5.2.jar
file.reference.sqlite-jdbc-3.7.2.jar=lib\\sqlite-jdbc-3.7.2.jar
file.reference.tritonus_aos-0.3.6.jar=lib\\tritonus_aos-0.3.6.jar
@ -72,7 +73,6 @@ javac.classpath=\
${file.reference.tritonus_share-0.3.6.jar}:\
${file.reference.AudioProcessing-1.0.jar}:\
${libs.jme3-libraries-effects.classpath}:\
${file.reference.jaudiotagger-2.2.0.jar}:\
${file.reference.commons-codec-1.4.jar}:\
${file.reference.commons-io-2.1.jar}:\
${file.reference.commons-lang3-3.1.jar}:\
@ -87,7 +87,9 @@ javac.classpath=\
${file.reference.xmlpull-1.1.3.1.jar}:\
${file.reference.xpp3_min-1.1.4c.jar}:\
${file.reference.xstream-1.4.2.jar}:\
${file.reference.sqlite-jdbc-3.7.2.jar}
${file.reference.sqlite-jdbc-3.7.2.jar}:\
${file.reference.BaseIO-1.0.jar}:\
${file.reference.PersiJ-1.0.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false

View File

@ -1,32 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
/**
* Exception thrown by the PersiJConstructor
*
* @author Darth Affe
*/
public class NoSuitableConstructorFoundException extends Exception {
NoSuitableConstructorFoundException() {
}
NoSuitableConstructorFoundException(String msg) {
super(msg);
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marks an Constructor for primary use by the PersiJConstructor
*
* @author Darth Affe
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.CONSTRUCTOR)
public @interface PersiJConstructor {
/**
* Returns the default state of the annotation
*
* @return true if default; false otherwise
*/
boolean isDefault();
/**
* Returns the id of the param mapping
*
* @return id of the param mapping
*/
int customParamMappingId() default -1;
}

View File

@ -1,172 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Mapping and object container for PersiJ
*
* @author Darth Affe
*/
public final class PersiJContainer {
private static final Logger logger = Logger.getLogger("org.wyrez.persij");
private final HashMap<Class, PersiJMapping> mappings = new HashMap<Class, PersiJMapping>();
public PersiJContainer() {
registerSingleton(PersiJContainer.class, this);
}
/**
* Registers a mapping
*
* @param type Type which should be mapped
*/
public final <T> void registerType(Class<T> type) {
registerType(type, false);
}
/**
* Registers a mapping
*
* @param type Type which should be mapped
* @param singleton Singleton indicator
*/
public final <T> void registerType(Class<T> type, boolean singleton) {
registerType(type, type, singleton);
}
/**
* Registers a mapping
*
* @param type Source-type which should be mapped
* @param mapping Target-type which should be mapped
*/
public final <T> void registerType(Class<T> type, Class<? extends T> mapping) {
registerType(type, mapping, false);
}
/**
* Registers a mapping
*
* @param type Source-type which should be mapped
* @param mapping Target-type which should be mapped
* @param singleton Singleton indicator
*/
public final <T> void registerType(Class<T> type, Class<? extends T> mapping, boolean singleton) {
mappings.put(type, new PersiJMapping(mapping, singleton));
}
/**
* Registers a singleton-mapping to an existing object
*
* @param type Source-type which should be mapped
* @param instance Singleton instance
*/
public final <T> void registerSingleton(Class<T> type, T instance) {
mappings.put(type, new PersiJMapping(type, instance));
}
/**
* Tests if the specified type is registered
*
* @param type Type which should be tested
* @return true if the type is registered; else otherwise
*/
public final boolean isTypeRegistered(Class type) {
return mappings.containsKey(type);
}
/**
* Creates an instance of the type mapped to the given type
*
* @param <T> Type to resolve
* @param type Class of the type to resolve
* @return Insance of T
*/
public final <T> T resolve(Class<T> type) {
PersiJMapping mapping = mappings.get(type);
if (mapping != null) {
try {
return (T) mapping.getInstance(this, null);
} catch (NoSuitableConstructorFoundException ex) {
logger.log(Level.WARNING, "Can't create object for type: "
+ type.getName(), ex);
return null;
}
} else {
logger.log(Level.WARNING, "Can't find a mapping for type: "
+ type.getName());
return null;
}
}
/**
* Creates an instance of the type mapped to the given type
*
* @param <T> Type to resolve
* @param type Class of the type to resolve
* @param paramMapping
* @return Instance of T
*/
public final <T> T resolve(Class<T> type, PersiJParamMapping paramMapping) {
PersiJMapping mapping = mappings.get(type);
if (mapping != null) {
try {
return (T) mapping.getInstance(this, paramMapping);
} catch (NoSuitableConstructorFoundException ex) {
logger.log(Level.WARNING, "Can't create object for type: "
+ type.getName(), ex);
return null;
}
} else {
logger.log(Level.WARNING, "Can't find a mapping for type: "
+ type.getName());
return null;
}
}
/**
* Creates an array with instances of the type mapped to the given type
*
* @param <T> Type to resolve
* @param type Class of the type to resolve
* @param number Size of the array
* @return Array of T
*/
public final <T> T[] resolve(Class<T> type, int number) {
PersiJMapping mapping = mappings.get(type);
if (mapping != null) {
try {
T[] array = (T[]) Array.newInstance(type, number);
return (T[]) mapping.getInstances(this, null, array);
} catch (NoSuitableConstructorFoundException ex) {
logger.log(Level.WARNING, "Can't create object for type: "
+ type.getName(), ex);
return null;
}
} else {
logger.log(Level.WARNING, "Can't find a mapping for type: "
+ type.getName());
return null;
}
}
}

View File

@ -1,208 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Darth Affe
*/
final class PersiJMapping {
private static final Logger logger = Logger.getLogger("org.wyrez.persij");
private Object singletonInstance;
private Class type;
private boolean singleton;
PersiJMapping(Class type, boolean singleton) {
this.type = type;
this.singleton = singleton;
}
PersiJMapping(Class type, Object singleton) {
this.type = type;
this.singleton = true;
singletonInstance = singleton;
}
final boolean isSingleton() {
return singleton;
}
/**
* Creates a new instance
*
* @param container Container to resolve missing dependencies
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @return New instance
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
final Object getInstance(PersiJContainer container, PersiJParamMapping paramMapping) throws NoSuitableConstructorFoundException {
if (isSingleton()) {
if (singletonInstance == null) {
singletonInstance = createInstance(container, paramMapping);
}
return singletonInstance;
} else {
return createInstance(container, paramMapping);
}
}
/**
* Creates an array with new instances
*
* @param container Container to resolve missing dependencies
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @param array Array which should be filled and returned
* @return New array with instances
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
final Object getInstances(PersiJContainer container, PersiJParamMapping paramMapping, Object[] array) throws NoSuitableConstructorFoundException {
if (isSingleton()) {
if (singletonInstance == null) {
singletonInstance = createInstance(container, paramMapping);
}
for (int i = 0; i < array.length; i++) {
array[i] = singletonInstance;
}
return array;
} else {
return createInstances(container, paramMapping, array);
}
}
/**
* Creates a new instance
*
* @param container Container to resolve missing dependencies
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @return New instance
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
private Object createInstance(PersiJContainer container, PersiJParamMapping paramMapping) throws NoSuitableConstructorFoundException {
Constructor constructor = getBestConstructor(container, paramMapping);
return createInstance(container, constructor, paramMapping);
}
/**
* Creates an array with new instances
*
* @param container Container to resolve missing dependencies
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @param array Array which should be filled and returned
* @return New array with instances
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
private Object createInstances(PersiJContainer container, PersiJParamMapping paramMapping, Object[] array) throws NoSuitableConstructorFoundException {
Constructor constructor = getBestConstructor(container, paramMapping);
for (int i = 0; i < array.length; i++) {
array[i] = createInstance(container, constructor, paramMapping);
}
return array;
}
/**
* Creates an instance using the given constructor
*
* @param container Container to resolve missing dependencies
* @param constructor Constructor to instantiate
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @return New instance
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
private Object createInstance(PersiJContainer container, Constructor constructor, PersiJParamMapping paramMapping) throws NoSuitableConstructorFoundException {
Object[] params;
if (paramMapping != null && paramMapping.getType() == type) {
params = paramMapping.getParams();
} else {
Class[] conParams = constructor.getParameterTypes();
int paramCount = conParams.length;
params = new Object[paramCount];
for (int i = 0; i < paramCount; i++) {
params[i] = container.resolve(conParams[i], paramMapping);
}
}
try {
return constructor.newInstance(params);
} catch (Exception ex) {
logger.log(Level.WARNING, "Error while creating instance of an object", ex);
return null;
}
}
/**
* Determines the best constructor to instantiate
*
* @param container Container to check registered types
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @return Best constructor to instantiate
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
private Constructor getBestConstructor(PersiJContainer container, PersiJParamMapping paramMapping) throws NoSuitableConstructorFoundException {
Constructor bestToCreate = null;
int paramCount = -1;
for (Constructor c : type.getConstructors()) {
Annotation annotation = c.getAnnotation(PersiJConstructor.class);
if (paramMapping != null && paramMapping.getType() == type) {
if (annotation != null && ((PersiJConstructor) annotation).customParamMappingId() == paramMapping.getParamMappingId()) {
bestToCreate = c;
break;
}
} else {
boolean possible = true;
for (Class t : c.getParameterTypes()) {
if (t.isPrimitive() || t == String.class || t == Object.class || !container.isTypeRegistered(t)) {
possible = false;
break;
}
}
if (possible) {
int pCount = c.getParameterTypes().length;
if (annotation != null) {
if (((PersiJConstructor) annotation).isDefault()) {
bestToCreate = c;
break;
}
} else if (pCount > paramCount) {
bestToCreate = c;
paramCount = pCount;
}
}
}
}
if (bestToCreate == null) {
throw new NoSuitableConstructorFoundException();
}
return bestToCreate;
}
}

View File

@ -1,65 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
/**
*
* @author Darth Affe
*/
public final class PersiJParamMapping {
private Class type;
private Object[] params;
private int paramMappingId;
public PersiJParamMapping(Class type, Object... params) {
this(-1, type, params);
}
public PersiJParamMapping(int paramMappingId, Class type, Object... params) {
this.type = type;
this.params = params;
this.paramMappingId = paramMappingId;
}
/**
* Returns the Type to which the ParamMapping belongs
*
* @return Type of the ParamMapping
*/
public final Class getType() {
return type;
}
/**
* Returns the mapped parameters
*
* @return Array with mapped parameters
*/
public final Object[] getParams() {
return params;
}
/**
* Returns the id of the mapping
*
* @return id of the mapping
*/
public final int getParamMappingId() {
return paramMappingId;
}
}

View File

@ -17,6 +17,7 @@
package org.wyrez.shootingstars.controls;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.shapes.EmitterShape;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;
@ -63,12 +64,13 @@ public class StarDeathControl extends BaseControl {
effect.setEndColor(new ColorRGBA(points.getColor().r,
points.getColor().g, points.getColor().b, 0f));
}
effect.setStartSize((Float) spatial.getUserData(UserDataKeys.SIZE));
effect.setStartSize((Float) spatial.getUserData(UserDataKeys.SIZE)*0.5f);
effect.setEndSize(0f);
effect.setHighLife(FX_TIME);
effect.setLowLife(0f);
effect.setLocalTranslation(spatial.getLocalTranslation());
effect.setParticlesPerSec(0f);
effect.setRandomAngle(true);
spatial.getParent().attachChild(effect);
spatial.setCullHint(Spatial.CullHint.Always);

View File

@ -64,10 +64,10 @@ public class StarPointControl extends BaseControl {
if (points > 1f) {
points -= 2f * tpf;
color = ColorHelper.calcColor(points / MAX_POINTS);
} else if (points < 1f) {
spatial.setUserData(UserDataKeys.HITTED, true); //TODO test
} else if (points <= 1f) {
points = 1f;
color = ColorHelper.calcColor(points / MAX_POINTS);
spatial.setUserData(UserDataKeys.HITTED, true);
}
material.setColor("Color", color);
} else {

View File

@ -16,7 +16,6 @@ package org.wyrez.shootingstars.data;
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import com.github.axet.vget.VGet;
import com.github.axet.vget.info.VideoInfo;
import com.github.axet.vget.info.VideoInfo.VideoQuality;
@ -30,6 +29,7 @@ import java.net.URL;
public class YTDownloader {
private File lastTarget;
private String lastTitle;
public YTDownloader() {
}
@ -50,6 +50,7 @@ public class YTDownloader {
VGet v = new VGet(info, new File(targetFolder));
v.download();
lastTarget = v.getTarget();
lastTitle = v.getVideo().getTitle();
System.out.println("success!");
return true;
} catch (Exception e) {
@ -70,4 +71,8 @@ public class YTDownloader {
public File getLastTarget() {
return lastTarget;
}
public String getLastTitle() {
return lastTitle;
}
}

View File

@ -35,18 +35,21 @@ public class GameSettings {
private boolean useVideo;
private String trackTitle;
private String trackArtist;
private int trackLength;
public GameSettings() {
}
public void setAudioFile(String audioFile) {
this.audioFile = audioFile;
this.useVideo = false;
}
public void setVideoFile(String videoFile) {
this.videoFile = videoFile;
this.useVideo = true;
}
public void useVideo(boolean useVideo) {
this.useVideo = useVideo;
}
public void setTrackTitle(String trackTitle) {
@ -57,6 +60,10 @@ public class GameSettings {
this.trackArtist = trackArtist;
}
public void setTrackLength(int length) {
this.trackLength = length;
}
public String getAudioFile() {
return audioFile;
}
@ -96,4 +103,8 @@ public class GameSettings {
public String getTrackTitle() {
return trackTitle;
}
public int getTrackLength() {
return trackLength;
}
}

View File

@ -19,11 +19,9 @@ package org.wyrez.shootingstars.game;
import com.jme3.asset.AssetManager;
import com.jme3.input.InputManager;
import com.jme3.light.AmbientLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
@ -41,6 +39,7 @@ import org.wyrez.shootingstars.helper.MathHelper;
import org.wyrez.shootingstars.helper.UserDataKeys;
import org.wyrez.shootingstars.mesh.HexPrism;
import org.wyrez.shootingstars.states.StateManager;
import org.wyrez.shootingstars.states.util.OptionSettings;
/**
*
@ -54,13 +53,15 @@ public class Player extends Node {
public Player(Node rootNode, StateManager stateManager, AssetManager assetManager,
ViewPort viewPort, GameGUI gui, InputManager inputManager, Camera camera,
AudioDataManager audioDataManager, Node starNode) {
AudioDataManager audioDataManager, Node starNode, OptionSettings settings) {
super("Player");
initPlayer(inputManager, camera, audioDataManager, gui);
if (settings.isShowWeaponEnabled()) {
initWeapon(assetManager);
initProjectile(rootNode);
initWeaponContainer();
}
initGhostProjectile(starNode);
addLight();
}

View File

@ -19,11 +19,6 @@ package org.wyrez.shootingstars.gui;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f;
import java.io.File;
import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.AudioHeader;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.wyrez.shootingstars.game.GameSettings;
import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.listener.FileMetaInfoListener;
@ -42,10 +37,10 @@ public class FileMetaInfoGUI extends Panel implements Gui {
private FileMetaInfoListener listener;
private GameSettings settings;
private ScreenHelper screenHelper;
private String fileName = "";
private String duration = "";
private String title = "";
private String artist = "";
private Label lblFileName;
private Label lblArtist;
private Label lblTitel;
private Label lblDuration;
public FileMetaInfoGUI(Screen screen, FileMetaInfoListener listener, GameSettings settings, ScreenHelper screenHelper) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f));
@ -64,45 +59,32 @@ public class FileMetaInfoGUI extends Panel implements Gui {
float buttonWidth = screenHelper.calcX(153.6f);
float labelFontSize = screenHelper.calcX(20f);
File file = null;
if(settings.useVideo()) {
file = new File(settings.getVideoFile());
} else {
file = new File(settings.getAudioFile());
}
readMetaData(file);
Label lblFileNameHead = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f)));
lblFileNameHead.setText("Track Name");
lblFileNameHead.setFontSize(labelFontSize);
Label lblFileName = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblFileName.setText(fileName);
lblFileName = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblFileName.setFontSize(labelFontSize);
Label lblArtistHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(50f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f)));
lblArtistHead.setText("Artist");
lblArtistHead.setFontSize(labelFontSize);
Label lblArtist = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(50f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblArtist.setText(artist);
lblArtist = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(50f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblArtist.setFontSize(labelFontSize);
Label lblTitelHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(100f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f)));
lblTitelHead.setText("Titel");
lblTitelHead.setFontSize(labelFontSize);
Label lblTitel = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(100f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblTitel.setText(title);
lblTitel = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(100f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblTitel.setFontSize(labelFontSize);
Label lblDurationHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(150f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f)));
lblDurationHead.setText("Duration");
lblDurationHead.setFontSize(labelFontSize);
Label lblDuration = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(150f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblDuration.setText(duration);
lblDuration = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(150f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblDuration.setFontSize(labelFontSize);
Button btnStartLoading = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(653f), startPointy + screenHelper.calcY(438.8f)), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
@ -135,27 +117,11 @@ public class FileMetaInfoGUI extends Panel implements Gui {
this.addChild(btnCancel);
}
private void readMetaData(File file) {
try {
fileName = file.getName();
AudioFile f = AudioFileIO.read(file);
Tag tag = f.getTag();
AudioHeader ah = f.getAudioHeader();
if (ah != null) {
duration = String.valueOf(ah.getTrackLength()) + " s";
}
if (tag != null) {
if (tag.hasField(FieldKey.TITLE)) {
title = tag.getFirst(FieldKey.TITLE);
settings.setTrackTitle(title);
}
artist = tag.getFirst(FieldKey.ARTIST);
settings.setTrackArtist(artist);
}
} catch (Exception ex) {
}
public void refresh() {
lblDuration.setText(String.valueOf(settings.getTrackLength()) + " s");
lblTitel.setText(settings.getTrackTitle());
lblArtist.setText(settings.getTrackArtist());
lblFileName.setText(new File(settings.getVideoFile()).getName());
}
public void attach() {

View File

@ -22,6 +22,8 @@ package org.wyrez.shootingstars.gui;
*/
public interface Gui {
public void refresh();
public void attach();
public void detach();

View File

@ -101,7 +101,7 @@ public class HighscoreGUI extends Panel implements Gui {
lblScorePoints.setFontSize(labelFontSize);
Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(600f), screenHelper.calcY(40f)));
lblScoreSongName.setText(score.getSongName());
lblScoreSongName.setFontSize(labelFontSize);
this.addChild(lblScoreName);
@ -124,4 +124,7 @@ public class HighscoreGUI extends Panel implements Gui {
this.addChild(lblScoreSongNameHead);
this.addChild(btnBack);
}
public void refresh() {
}
}

View File

@ -109,6 +109,9 @@ public class MenuGUI extends Panel implements Gui {
this.addChild(lblShootingStars);
}
public void refresh() {
}
public void attach() {
screen.addElement(this);
}

View File

@ -42,10 +42,8 @@ public class OptionsGUI extends Panel implements Gui {
private OptionsListener listener;
private OptionSettings settings;
private ScreenHelper screenHelper;
//General Controls
private TextField txtPlayerName;
//Video Controls
private ComboBox cboResolution;
private ComboBox cboFrequency;
@ -321,4 +319,7 @@ public class OptionsGUI extends Panel implements Gui {
settings.save();
}
public void refresh() {
}
}

View File

@ -94,6 +94,9 @@ public class SelectTrackGUI extends Panel implements Gui{
this.addChild(btnCancel);
}
public void refresh() {
}
public void attach() {
screen.addElement(this);
}

View File

@ -96,6 +96,9 @@ public class YTDownloadGUI extends Panel implements Gui{
this.addChild(btnCancel);
}
public void refresh() {
}
public void attach() {
screen.addElement(this);
}
@ -103,5 +106,4 @@ public class YTDownloadGUI extends Panel implements Gui{
public void detach() {
screen.removeElement(this);
}
}

View File

@ -32,12 +32,10 @@ import tonegod.gui.core.Screen;
public class FileMetaInfoState extends AbstractAppState implements FileMetaInfoListener {
private StateManager stateManager;
private GameSettings settings;
private Gui gui;
public FileMetaInfoState(Screen screen, StateManager stateManager, GameSettings settings, ScreenHelper screenHelper) {
this.stateManager = stateManager;
this.settings = settings;
this.gui = new FileMetaInfoGUI(screen, this, settings, screenHelper);
}
@ -51,6 +49,7 @@ public class FileMetaInfoState extends AbstractAppState implements FileMetaInfoL
@Override
public void stateAttached(AppStateManager stateManager) {
gui.refresh();
gui.attach();
}

View File

@ -95,7 +95,12 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
this.optionSettings = optionSettings;
this.highscoreManager = highscoreManager;
if (settings.useVideo()) {
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
} else {
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet",
"--audio-visual=visual", "--effect-list=scope");
}
this.settings = settings;
@ -113,6 +118,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(settings.getVideoFormat(),
settings.getVideoWidth(), settings.getVideoHeight(),
settings.getVideoWidth() * settings.getVideoDepth(), cinema);
mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventListenerBase() {
@Override
public void finished(MediaPlayer mp) {
@ -130,7 +136,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
public void loadPlayer() {
starNode = new Node();
player = new Player(rootNode, stateManager, assetManager, viewPort, gui,
inputManager, camera, audioDataManager, starNode);
inputManager, camera, audioDataManager, starNode, optionSettings);
gui.setPlayer(player);
@ -146,8 +152,8 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
public void start() {
gui.setStart();
inputManager.setCursorVisible(false);
mediaPlayer.setVolume(optionSettings.getMusicVolume() *
Math.round((float)optionSettings.getMasterVolume() / 100f));
mediaPlayer.setVolume(optionSettings.getMusicVolume()
* Math.round((float) optionSettings.getMasterVolume() / 100f));
mediaPlayer.play();
setRunning(true);
}

View File

@ -18,6 +18,7 @@ package org.wyrez.shootingstars.states;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.sun.jna.Memory;
import java.io.File;
import javax.swing.JFileChooser;
import org.wyrez.shootingstars.game.GameSettings;
@ -25,6 +26,10 @@ import org.wyrez.shootingstars.gui.SelectTrackGUI;
import org.wyrez.shootingstars.gui.listener.SelectFileListener;
import org.wyrez.shootingstars.helper.ScreenHelper;
import tonegod.gui.core.Screen;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.direct.BufferFormat;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
import uk.co.caprica.vlcj.player.direct.RenderCallback;
/**
*
@ -32,6 +37,8 @@ import tonegod.gui.core.Screen;
*/
public class SelectTrackState extends AbstractAppState implements SelectFileListener {
private static final int SLEEP = 1000;
/**/
private StateManager stateManager;
private GameSettings settings;
private SelectTrackGUI gui;
@ -59,10 +66,35 @@ public class SelectTrackState extends AbstractAppState implements SelectFileList
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = jFileChooser.getSelectedFile();
settings.setVideoFile(file.getPath());
readMetadata(settings.getVideoFile());
stateManager.setState(State.FILEMETAINFO);
}
}
private void readMetadata(String file) {
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
DirectMediaPlayer mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(1, 1, new RenderCallback() {
public void display(DirectMediaPlayer dmp, Memory[] memorys, BufferFormat bf) {
}
});
mediaPlayer.setVolume(0);
mediaPlayer.prepareMedia(file);
mediaPlayer.play();
try {
Thread.sleep(SLEEP);
} catch (Exception ex) {
}
settings.useVideo(mediaPlayer.getVideoTrackCount() > 0);
settings.setTrackTitle(mediaPlayer.getMediaMeta().getTitle());
settings.setTrackArtist(mediaPlayer.getMediaMeta().getArtist());
settings.setTrackLength(Math.round((float) mediaPlayer.getLength() / 1000f));
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayerFactory.release();
}
public void downloadYT() {
stateManager.setState(State.YTDOWNLOAD);
}

View File

@ -18,9 +18,11 @@ package org.wyrez.shootingstars.states;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.sun.jna.Memory;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.wyrez.baseio.config.FlatFileConfig;
import org.wyrez.shootingstars.data.YTDownloader;
import org.wyrez.shootingstars.game.GameSettings;
import org.wyrez.shootingstars.gui.YTDownloadGUI;
@ -28,6 +30,10 @@ import org.wyrez.shootingstars.gui.listener.YTDownloadListener;
import org.wyrez.shootingstars.helper.PathHelper;
import org.wyrez.shootingstars.helper.ScreenHelper;
import tonegod.gui.core.Screen;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.direct.BufferFormat;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
import uk.co.caprica.vlcj.player.direct.RenderCallback;
/**
*
@ -35,6 +41,10 @@ import tonegod.gui.core.Screen;
*/
public class YTDownloadState extends AbstractAppState implements YTDownloadListener {
private static final int SLEEP = 1000;
private static final String META_EXTENSION = ".meta";
private static final String KEY_TITLE = "Title";
private static final String KEY_ARTIST = "Artist";
private static final Pattern YT_LINK_PATTERN = Pattern.compile("\\?v=[^\\&]*\\&??");
/**/
private StateManager stateManager;
@ -77,8 +87,10 @@ public class YTDownloadState extends AbstractAppState implements YTDownloadListe
path = PathHelper.getCacheFolder() + identifier
+ targetPath.substring(targetPath.lastIndexOf("."), targetPath.length());
new File(targetPath).renameTo(new File(path));
createMetadataFile(path);
}
settings.setVideoFile(path);
readMetadata();
stateManager.setState(State.FILEMETAINFO);
} catch (Exception ex) {
stateManager.setState(State.MENU);
@ -95,6 +107,38 @@ public class YTDownloadState extends AbstractAppState implements YTDownloadListe
return null;
}
private void createMetadataFile(String file) {
FlatFileConfig config = new FlatFileConfig(file + META_EXTENSION);
config.putString(KEY_TITLE, downloader.getLastTitle());
config.putString(KEY_ARTIST, "Youtube download");
config.save();
}
private void readMetadata() {
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
DirectMediaPlayer mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(1, 1, new RenderCallback() {
public void display(DirectMediaPlayer dmp, Memory[] memorys, BufferFormat bf) {
}
});
mediaPlayer.setVolume(0);
mediaPlayer.prepareMedia(settings.getVideoFile());
mediaPlayer.play();
try {
Thread.sleep(SLEEP);
} catch (Exception ex) {
}
FlatFileConfig config = new FlatFileConfig(settings.getVideoFile() + META_EXTENSION);
settings.setTrackTitle(config.getString(KEY_TITLE));
settings.setTrackArtist(config.getString(KEY_ARTIST));
settings.useVideo(mediaPlayer.getVideoTrackCount() > 0);
settings.setTrackLength(Math.round((float) mediaPlayer.getLength() / 1000f));
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayerFactory.release();
}
public void cancel() {
stateManager.setState(State.MENU);
}