improved metadata analysis, added persij as library, added refresh to gui interface
This commit is contained in:
parent
d37263b4bf
commit
4513c6b6bb
BIN
ShootingStars/lib/BaseIO-1.0.jar
Normal file
BIN
ShootingStars/lib/BaseIO-1.0.jar
Normal file
Binary file not shown.
BIN
ShootingStars/lib/PersiJ-1.0.jar
Normal file
BIN
ShootingStars/lib/PersiJ-1.0.jar
Normal file
Binary file not shown.
Binary file not shown.
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
||||
@ -56,7 +56,7 @@ public class StarPointControl extends BaseControl {
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
if ((Boolean)spatial.getUserData(UserDataKeys.HITTED) && !isHitted) {
|
||||
if ((Boolean) spatial.getUserData(UserDataKeys.HITTED) && !isHitted) {
|
||||
player.setUserData(UserDataKeys.POINTS, (Integer) (player.getUserData(UserDataKeys.POINTS))
|
||||
+ (int) Math.round(points));
|
||||
isHitted = true;
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
initWeapon(assetManager);
|
||||
initProjectile(rootNode);
|
||||
initWeaponContainer();
|
||||
if (settings.isShowWeaponEnabled()) {
|
||||
initWeapon(assetManager);
|
||||
initProjectile(rootNode);
|
||||
initWeaponContainer();
|
||||
}
|
||||
initGhostProjectile(starNode);
|
||||
addLight();
|
||||
}
|
||||
@ -95,7 +96,7 @@ public class Player extends Node {
|
||||
geom2.setMaterial(Materials.WEAPON.create());
|
||||
geom2.move(0f, 0.25f, -5f);
|
||||
projectile.attachChild(geom2);
|
||||
|
||||
|
||||
projectile.addControl(new WeaponProjectileControl(rootNode, this));
|
||||
}
|
||||
|
||||
@ -111,13 +112,13 @@ public class Player extends Node {
|
||||
|
||||
this.attachChild(weaponContainer);
|
||||
}
|
||||
|
||||
|
||||
private void initGhostProjectile(Node starNode) {
|
||||
Geometry ghostProjectile = new Geometry("ghostProjectile", new Box(0.1f, 0.1f, 2500f));
|
||||
ghostProjectile.setMaterial(Materials.UNSHADED.create());
|
||||
ghostProjectile.setCullHint(CullHint.Always);
|
||||
ghostProjectile.move(0f,0f,2510f);
|
||||
ghostProjectile.addControl(new WeaponProjectileCollisionControl(starNode,this));
|
||||
ghostProjectile.move(0f, 0f, 2510f);
|
||||
ghostProjectile.addControl(new WeaponProjectileCollisionControl(starNode, this));
|
||||
this.attachChild(ghostProjectile);
|
||||
}
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ import org.wyrez.shootingstars.states.GameState;
|
||||
*
|
||||
* @author Darth Affe
|
||||
*/
|
||||
public class StarManager{
|
||||
public class StarManager {
|
||||
|
||||
private static final Random random;
|
||||
private static final float MAX_STAR_SIZE = 15f;
|
||||
@ -93,7 +93,7 @@ public class StarManager{
|
||||
star.addControl(new StarFaceControl(player));
|
||||
star.addControl(new StarDeathControl());
|
||||
star.addControl(new StarPointControl(player, value));
|
||||
|
||||
|
||||
starNode.attachChild(star);
|
||||
}
|
||||
|
||||
|
||||
@ -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));
|
||||
@ -63,48 +58,35 @@ public class FileMetaInfoGUI extends Panel implements Gui {
|
||||
float marginLeft = screenHelper.calcX(110f);
|
||||
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))) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -113,7 +95,7 @@ public class FileMetaInfoGUI extends Panel implements Gui {
|
||||
};
|
||||
btnStartLoading.setText("Play");
|
||||
btnStartLoading.setFontSize(labelFontSize);
|
||||
|
||||
|
||||
Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(836f), startPointy + screenHelper.calcY(438.8f)), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -122,7 +104,7 @@ public class FileMetaInfoGUI extends Panel implements Gui {
|
||||
};
|
||||
btnCancel.setText("Cancel");
|
||||
btnCancel.setFontSize(labelFontSize);
|
||||
|
||||
|
||||
this.addChild(lblFileNameHead);
|
||||
this.addChild(lblFileName);
|
||||
this.addChild(lblArtistHead);
|
||||
@ -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() {
|
||||
|
||||
@ -22,6 +22,8 @@ package org.wyrez.shootingstars.gui;
|
||||
*/
|
||||
public interface Gui {
|
||||
|
||||
public void refresh();
|
||||
|
||||
public void attach();
|
||||
|
||||
public void detach();
|
||||
|
||||
@ -45,7 +45,7 @@ public class HighscoreGUI extends Panel implements Gui {
|
||||
this.highscoreManager = highscoreManager;
|
||||
this.screenHelper = screenHelper;
|
||||
this.setIgnoreMouse(true);
|
||||
this.setIsVisible(false);
|
||||
this.setIsVisible(false);
|
||||
create();
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class HighscoreGUI extends Panel implements Gui {
|
||||
float marginScoreSongNameLeft = screenHelper.calcX(600f);
|
||||
|
||||
float marginScoreTop = screenHelper.calcY(50f);
|
||||
|
||||
|
||||
float labelFontSize = screenHelper.calcX(20f);
|
||||
|
||||
List<Score> highscores = highscoreManager.getScores();
|
||||
@ -84,12 +84,12 @@ public class HighscoreGUI extends Panel implements Gui {
|
||||
lblScoreSongNameHead.setFontSize(labelFontSize);
|
||||
|
||||
int maxScores = 0;
|
||||
if(highscores.size() > 10) {
|
||||
if (highscores.size() > 10) {
|
||||
maxScores = 10;
|
||||
} else {
|
||||
maxScores = highscores.size();
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < maxScores; i++) {
|
||||
Score score = highscores.get(i);
|
||||
Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f)));
|
||||
@ -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() {
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,12 +40,12 @@ public class MenuGUI extends Panel implements Gui {
|
||||
this.listener = listener;
|
||||
this.screenHelper = screenHelper;
|
||||
this.setIgnoreMouse(true);
|
||||
this.setIsVisible(false);
|
||||
this.setIsVisible(false);
|
||||
create();
|
||||
}
|
||||
|
||||
private void create() {
|
||||
|
||||
|
||||
float startPointx = screenHelper.calcX(256f);
|
||||
float startPointy = screenHelper.calcY(252f);
|
||||
float labelFontSize = screenHelper.calcX(89f);
|
||||
@ -56,11 +56,11 @@ public class MenuGUI extends Panel implements Gui {
|
||||
float marginButtonTop = screenHelper.calcY(25f);
|
||||
float distanceLabelLabely = screenHelper.calcY(60f);
|
||||
float buttonFontSize = screenHelper.calcX(20f);
|
||||
|
||||
|
||||
Label lblWyrez = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(300), screenHelper.calcY(40)));
|
||||
lblWyrez.setFontSize(labelFontSize);
|
||||
lblWyrez.setText("Wyrez");
|
||||
|
||||
|
||||
Label lblShootingStars = new Label(screen, new Vector2f(startPointx, startPointy + distanceLabelLabely), new Vector2f(screenHelper.calcX(500), screenHelper.calcY(40)));
|
||||
lblShootingStars.setFontSize(labelFontSize);
|
||||
lblShootingStars.setText("Shooting Stars");
|
||||
@ -73,7 +73,7 @@ public class MenuGUI extends Panel implements Gui {
|
||||
};
|
||||
btnStart.setText("Start Game");
|
||||
btnStart.setFontSize(buttonFontSize);
|
||||
|
||||
|
||||
Button btnHighscore = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + marginButtonTop), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -82,7 +82,7 @@ public class MenuGUI extends Panel implements Gui {
|
||||
};
|
||||
btnHighscore.setText("Highscore");
|
||||
btnHighscore.setFontSize(buttonFontSize);
|
||||
|
||||
|
||||
Button btnOptions = new ButtonBase(screen, new Vector2f(startPointx + buttonLabelDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -91,7 +91,7 @@ public class MenuGUI extends Panel implements Gui {
|
||||
};
|
||||
btnOptions.setText("Options");
|
||||
btnOptions.setFontSize(buttonFontSize);
|
||||
|
||||
|
||||
Button btnExit = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -109,6 +109,9 @@ public class MenuGUI extends Panel implements Gui {
|
||||
this.addChild(lblShootingStars);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
}
|
||||
|
||||
public void attach() {
|
||||
screen.addElement(this);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -83,7 +81,7 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
|
||||
float buttonWidth = screenHelper.calcX(153.6f);
|
||||
float buttonHeight = screenHelper.calcY(40f);
|
||||
|
||||
|
||||
float labelFontSize = screenHelper.calcX(20f);
|
||||
|
||||
createGeneral(labelFontSize);
|
||||
@ -123,10 +121,10 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
Label lblPlayerName = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(120f), screenHelper.calcY(40f)));
|
||||
lblPlayerName.setText("Player Name");
|
||||
lblPlayerName.setFontSize(labelFontSize);
|
||||
|
||||
|
||||
txtPlayerName = new TextField(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(7f)), new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f)));
|
||||
txtPlayerName.setFontSize(labelFontSize);
|
||||
|
||||
|
||||
this.addChild(lblPlayerName);
|
||||
this.addChild(txtPlayerName);
|
||||
}
|
||||
@ -138,13 +136,13 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
float marginLeftControls = screenHelper.calcX(115.8f);
|
||||
float labelWitdh = screenHelper.calcX(120f);
|
||||
float labelHeight = screenHelper.calcY(40f);
|
||||
|
||||
|
||||
float comboBoxWidth = screenHelper.calcX(200f);
|
||||
float comboBoxHeight = screenHelper.calcY(30f);
|
||||
|
||||
|
||||
float checkBoxWitdh = screenHelper.calcX(20f);
|
||||
float checkBoxHeight = screenHelper.calcX(20f);
|
||||
|
||||
|
||||
float sliderWitdh = screenHelper.calcX(200f);
|
||||
float sliderHeight = screenHelper.calcY(30f);
|
||||
|
||||
@ -165,7 +163,7 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
lblPostProcessing.setFontSize(labelFontSize);
|
||||
|
||||
chkShowWeapon = new CheckBox(screen, new Vector2f(startPointx + marginLeftControls + screenHelper.calcX(800f), startPointy + screenHelper.calcY(12f)), new Vector2f(checkBoxWitdh, checkBoxHeight));
|
||||
|
||||
|
||||
Label lblResolution = new Label(screen, "lblResolution", new Vector2f(startPointx, startPointy + screenHelper.calcY(50f)), new Vector2f(labelWitdh, labelHeight));
|
||||
lblResolution.setText("Resolution");
|
||||
lblResolution.setFontSize(labelFontSize);
|
||||
@ -192,9 +190,9 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
cboFrequency.setFontSize(labelFontSize);
|
||||
for (String s : DisplayHelper.getFrequencys()) {
|
||||
cboFrequency.addListItem(s, s);
|
||||
}
|
||||
}
|
||||
|
||||
Label lblParticleDensity = new Label(screen, "lblParticleDensity", new Vector2f(startPointx + screenHelper.calcX(800f), startPointy +screenHelper.calcY(50f)), new Vector2f(labelWitdh, labelHeight));
|
||||
Label lblParticleDensity = new Label(screen, "lblParticleDensity", new Vector2f(startPointx + screenHelper.calcX(800f), startPointy + screenHelper.calcY(50f)), new Vector2f(labelWitdh, labelHeight));
|
||||
lblParticleDensity.setText("Particle Density");
|
||||
lblParticleDensity.setFontSize(labelFontSize);
|
||||
|
||||
@ -205,7 +203,7 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
};
|
||||
sldParticleDensity.setStepIntegerRange(0, 3, 1);
|
||||
|
||||
|
||||
|
||||
this.addChild(lblVSync);
|
||||
this.addChild(chkVSync);
|
||||
this.addChild(lblFullscreen);
|
||||
@ -224,10 +222,10 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
float startPointx = screenHelper.calcX(64f);
|
||||
float startPointy = screenHelper.calcY(290f);
|
||||
float marginLeftControls = screenHelper.calcX(115.8f);
|
||||
|
||||
|
||||
float labelWitdh = screenHelper.calcX(120f);
|
||||
float labelHeight = screenHelper.calcY(40f);
|
||||
|
||||
|
||||
float sliderWitdh = screenHelper.calcX(200f);
|
||||
float sliderHeight = screenHelper.calcY(30f);
|
||||
|
||||
@ -245,7 +243,7 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
Label lblFXVolume = new Label(screen, "lblFXVolume", new Vector2f(startPointx + screenHelper.calcX(400f), startPointy), new Vector2f(labelWitdh, labelHeight));
|
||||
lblFXVolume.setText("Menu Volume");
|
||||
lblFXVolume.setFontSize(labelFontSize);
|
||||
|
||||
|
||||
sldMenuVolume = new Slider(screen, new Vector2f(startPointx + marginLeftControls + screenHelper.calcX(400f), startPointy + screenHelper.calcY(7f)), new Vector2f(sliderWitdh, sliderHeight), Slider.Orientation.HORIZONTAL, false) {
|
||||
@Override
|
||||
public void onChange(int selectedIndex, Object value) {
|
||||
@ -277,7 +275,7 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
|
||||
//General
|
||||
txtPlayerName.setText(settings.getUsername());
|
||||
|
||||
|
||||
//Video
|
||||
setComboBoxValue(cboResolution, resolution);
|
||||
setComboBoxValue(cboFrequency, String.valueOf(settings.getFrequency()));
|
||||
@ -303,7 +301,7 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
private void saveControlValues() {
|
||||
//General
|
||||
settings.setUsername(txtPlayerName.getText());
|
||||
|
||||
|
||||
//Video
|
||||
String resolution[] = cboResolution.getSelectedListItem().getValue().toString().split(" x ");
|
||||
settings.setWidth(Integer.parseInt(resolution[0]));
|
||||
@ -321,4 +319,7 @@ public class OptionsGUI extends Panel implements Gui {
|
||||
|
||||
settings.save();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,11 +30,11 @@ import tonegod.gui.core.Screen;
|
||||
*
|
||||
* @author Snowsun
|
||||
*/
|
||||
public class SelectTrackGUI extends Panel implements Gui{
|
||||
public class SelectTrackGUI extends Panel implements Gui {
|
||||
|
||||
private SelectFileListener listener;
|
||||
private ScreenHelper screenHelper;
|
||||
|
||||
|
||||
public SelectTrackGUI(Screen screen, SelectFileListener listener, ScreenHelper screenHelper) {
|
||||
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
|
||||
this.listener = listener;
|
||||
@ -43,7 +43,7 @@ public class SelectTrackGUI extends Panel implements Gui{
|
||||
this.setIsVisible(false);
|
||||
create();
|
||||
}
|
||||
|
||||
|
||||
private void create() {
|
||||
float startPointx = screenHelper.calcX(576f);
|
||||
float startPointy = screenHelper.calcY(260f);
|
||||
@ -56,7 +56,7 @@ public class SelectTrackGUI extends Panel implements Gui{
|
||||
float labelWitdh = screenHelper.calcX(100f);
|
||||
float labelHeight = screenHelper.calcY(40f);
|
||||
float buttonFontSize = screenHelper.calcX(20f);
|
||||
|
||||
|
||||
Button btnSelectFile = new ButtonBase(screen, new Vector2f(startPointx, startPointy), new Vector2f(buttonWidth, buttonHeight)) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -65,11 +65,11 @@ public class SelectTrackGUI extends Panel implements Gui{
|
||||
};
|
||||
btnSelectFile.setText("Select File");
|
||||
btnSelectFile.setFontSize(buttonFontSize);
|
||||
|
||||
|
||||
Label lblOr = new Label(screen, new Vector2f(startPointx + marginLabelOrLeft, startPointy + marginLabelOrTop), new Vector2f(labelWitdh, labelHeight));
|
||||
lblOr.setFontSize(labelFontSize);
|
||||
lblOr.setText("Or");
|
||||
|
||||
|
||||
Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop), new Vector2f(buttonWidth, buttonHeight)) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -78,7 +78,7 @@ public class SelectTrackGUI extends Panel implements Gui{
|
||||
};
|
||||
btnYTDownload.setText("YT Download");
|
||||
btnYTDownload.setFontSize(buttonFontSize);
|
||||
|
||||
|
||||
Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop + screenHelper.calcY(114f)), new Vector2f(buttonWidth, buttonHeight)) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -87,13 +87,16 @@ public class SelectTrackGUI extends Panel implements Gui{
|
||||
};
|
||||
btnCancel.setText("Cancel");
|
||||
btnCancel.setFontSize(buttonFontSize);
|
||||
|
||||
|
||||
this.addChild(btnSelectFile);
|
||||
this.addChild(lblOr);
|
||||
this.addChild(btnYTDownload);
|
||||
this.addChild(btnCancel);
|
||||
}
|
||||
|
||||
|
||||
public void refresh() {
|
||||
}
|
||||
|
||||
public void attach() {
|
||||
screen.addElement(this);
|
||||
}
|
||||
|
||||
@ -31,11 +31,11 @@ import tonegod.gui.core.Screen;
|
||||
*
|
||||
* @author Snowsun
|
||||
*/
|
||||
public class YTDownloadGUI extends Panel implements Gui{
|
||||
public class YTDownloadGUI extends Panel implements Gui {
|
||||
|
||||
private YTDownloadListener listener;
|
||||
private ScreenHelper screenHelper;
|
||||
|
||||
|
||||
public YTDownloadGUI(Screen screen, YTDownloadListener listener, ScreenHelper screenHelper) {
|
||||
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
|
||||
this.listener = listener;
|
||||
@ -44,7 +44,7 @@ public class YTDownloadGUI extends Panel implements Gui{
|
||||
this.setIsVisible(false);
|
||||
create();
|
||||
}
|
||||
|
||||
|
||||
private void create() {
|
||||
float startPointx = screenHelper.calcX(384f);
|
||||
float startPointy = screenHelper.calcY(324f);
|
||||
@ -58,20 +58,20 @@ public class YTDownloadGUI extends Panel implements Gui{
|
||||
float marginYTButtonTop = screenHelper.calcY(72f);
|
||||
float labelWitdh = screenHelper.calcX(160f);
|
||||
float labelHeight = screenHelper.calcY(40f);
|
||||
|
||||
|
||||
float buttonFontSize = screenHelper.calcX(20f);
|
||||
float buttonHeight = screenHelper.calcY(40f);
|
||||
float textFieldHeight = screenHelper.calcY(40f);
|
||||
|
||||
|
||||
|
||||
|
||||
Label lblYTLink = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(labelWitdh, labelHeight));
|
||||
lblYTLink.setFontSize(labelFontSize);
|
||||
lblYTLink.setText("YT Link");
|
||||
|
||||
final TextField txtYTLink = new TextField(screen,"txtYTLink", new Vector2f(startPointx + marginTextFieldLeft, startPointy + marginTextFieldTop), new Vector2f(textFieldWitdh, textFieldHeight));
|
||||
|
||||
final TextField txtYTLink = new TextField(screen, "txtYTLink", new Vector2f(startPointx + marginTextFieldLeft, startPointy + marginTextFieldTop), new Vector2f(textFieldWitdh, textFieldHeight));
|
||||
txtYTLink.setType(TextField.Type.DEFAULT);
|
||||
txtYTLink.setFontSize(buttonFontSize);
|
||||
|
||||
|
||||
Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx + marginYTButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, buttonHeight)) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -80,7 +80,7 @@ public class YTDownloadGUI extends Panel implements Gui{
|
||||
};
|
||||
btnYTDownload.setText("Download");
|
||||
btnYTDownload.setFontSize(buttonFontSize);
|
||||
|
||||
|
||||
Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx + marginCancelButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, buttonHeight)) {
|
||||
@Override
|
||||
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
|
||||
@ -89,13 +89,16 @@ public class YTDownloadGUI extends Panel implements Gui{
|
||||
};
|
||||
btnCancel.setText("Cancel");
|
||||
btnCancel.setFontSize(buttonFontSize);
|
||||
|
||||
|
||||
this.addChild(lblYTLink);
|
||||
this.addChild(txtYTLink);
|
||||
this.addChild(btnYTDownload);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -95,7 +95,12 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
||||
this.optionSettings = optionSettings;
|
||||
this.highscoreManager = highscoreManager;
|
||||
|
||||
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
|
||||
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);
|
||||
}
|
||||
@ -238,13 +244,13 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
||||
|
||||
public void finished() {
|
||||
String songName = settings.getTrackArtist() + " - " + settings.getTrackTitle();
|
||||
|
||||
if(settings.useVideo()) {
|
||||
|
||||
if (settings.useVideo()) {
|
||||
highscoreManager.addScore(songName, optionSettings.getUsername(), Integer.valueOf(player.getUserData(UserDataKeys.POINTS).toString()));
|
||||
} else {
|
||||
highscoreManager.addScore(songName, optionSettings.getUsername(), Integer.valueOf(player.getUserData(UserDataKeys.POINTS).toString()));
|
||||
}
|
||||
|
||||
|
||||
stateManager.setState(State.HIGHSCORE);
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
@ -39,7 +46,7 @@ public class SelectTrackState extends AbstractAppState implements SelectFileList
|
||||
public SelectTrackState(Screen screen, StateManager stateManager, GameSettings settings, ScreenHelper screenHelper) {
|
||||
this.stateManager = stateManager;
|
||||
this.settings = settings;
|
||||
this.gui = new SelectTrackGUI(screen, this,screenHelper);
|
||||
this.gui = new SelectTrackGUI(screen, this, screenHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user