diff --git a/res/raw/workaround_1min.mp3 b/res/raw/workaround_1min.mp3 deleted file mode 100644 index 199d19c..0000000 Binary files a/res/raw/workaround_1min.mp3 and /dev/null differ diff --git a/src/com/lsu/vizeq/MyApplication.java b/src/com/lsu/vizeq/MyApplication.java index cf8dc2d..6c5dead 100644 --- a/src/com/lsu/vizeq/MyApplication.java +++ b/src/com/lsu/vizeq/MyApplication.java @@ -22,15 +22,16 @@ public class MyApplication extends Application { public String myName = ""; public String zipcode = null; public String myIp; - public boolean joined = false; - public boolean hosting = false; + public boolean joined; + public boolean hosting; public JedisPool jedisPool = new JedisPool(new JedisPoolConfig(), Redis.host, Redis.port); String brand = Build.BRAND; // for getting BrandName String model = Build.MODEL; // for getting Model of the device public static boolean doFlash; public static boolean doBackground; - public static boolean tapToFlash = false; + public static boolean tapToFlash; public static boolean nativeAnalysis; + public static boolean foundSound; @Override public void onCreate() { diff --git a/src/com/lsu/vizeq/RoleActivity.java b/src/com/lsu/vizeq/RoleActivity.java index 1a9df70..662af97 100644 --- a/src/com/lsu/vizeq/RoleActivity.java +++ b/src/com/lsu/vizeq/RoleActivity.java @@ -1,5 +1,7 @@ package com.lsu.vizeq; +import com.lsu.vizeq.util.TunnelPlayerWorkaround; + import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; @@ -118,18 +120,14 @@ protected void onCreate(Bundle savedInstanceState) myapp = (MyApplication) this.getApplicationContext(); - //final String useAwesome = SystemProperties.get("persist.sys.media.use-awesome"); final String usesTunnel = SystemProperties.get("tunnel.decode"); - - //Toast.makeText(this, "Awesome Player audio value: " + useAwesome + "\n" - //+ "Tunnel Player audio value: " + usesTunnel, Toast.LENGTH_LONG).show(); - if (usesTunnel.compareTo("true") == 0) + //Note: when using native analysis, if a debugger is attached, it usually falls behind + if (usesTunnel.compareTo("true") == 0 || !MyApplication.foundSound) { MyApplication.nativeAnalysis = true; LibSpotifyWrapper.nativeAnalysis = true; - } - + } findViewById(R.id.DJ).setOnTouchListener(new View.OnTouchListener() { diff --git a/src/com/lsu/vizeq/VizEQ.java b/src/com/lsu/vizeq/VizEQ.java index a52ce2a..b758cd3 100644 --- a/src/com/lsu/vizeq/VizEQ.java +++ b/src/com/lsu/vizeq/VizEQ.java @@ -8,6 +8,7 @@ import android.media.AudioManager; import android.media.MediaPlayer; +import android.media.audiofx.Visualizer; import android.os.Bundle; import android.app.ActionBar; import android.app.Activity; @@ -74,29 +75,62 @@ protected void onCreate(Bundle savedInstanceState) //load anything if necessary + final Visualizer visualizer = new Visualizer(0); + if (visualizer.getEnabled()) { + visualizer.setEnabled(false); + } + visualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[0]); + Visualizer.OnDataCaptureListener captureListener = new Visualizer.OnDataCaptureListener() { + + @Override + public void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate) + { + for (int i = 0; i < fft.length; i++) + { + if (fft[i] != 0) + MyApplication.foundSound = true; + } + } + + @Override + public void onWaveFormDataCapture(Visualizer visualizer, byte[] waveform, int samplingRate) + { + for (int i = 0; i < waveform.length; i++) + { + if (waveform[i] != -128) + MyApplication.foundSound = true; + } + } + + }; + visualizer.setDataCaptureListener(captureListener, Visualizer.getMaxCaptureRate()/4, true, true); + visualizer.setEnabled(true); + Thread splashThread = new Thread() { public void run() { - try - { - MediaPlayer mediaPlayer = MediaPlayer.create(VizEQ.this, R.raw.vizeqintro); - AudioManager audio = (AudioManager) VizEQ.this.getSystemService(VizEQ.this.AUDIO_SERVICE); - if (audio.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) mediaPlayer.start(); // no need to call prepare(); create() does that for you - sleep(mediaPlayer.getDuration()); //length of track - mediaPlayer.release(); - } - catch (Exception e) - { -// Log.d("Activity", "Login activity not started."); - } - finally - { - - finish(); - Intent nextIntent = new Intent(VizEQ.this, RoleActivity.class); - startActivity(nextIntent); - } - } + try + { + MediaPlayer mediaPlayer = MediaPlayer.create(VizEQ.this, R.raw.vizeqintro); + + //AudioManager audio = (AudioManager) VizEQ.this.getSystemService(Context.AUDIO_SERVICE); + //if (audio.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) + mediaPlayer.start(); + sleep(mediaPlayer.getDuration()); //length of track + mediaPlayer.release(); + visualizer.release(); + } + catch (Exception e) + { + + } + finally + { + finish(); + Intent nextIntent = new Intent(VizEQ.this, RoleActivity.class); + startActivity(nextIntent); + } + } }; splashThread.start(); diff --git a/src/com/lsu/vizeq/util/SystemPropertiesProxy.java b/src/com/lsu/vizeq/util/SystemPropertiesProxy.java deleted file mode 100644 index 8ece1cf..0000000 --- a/src/com/lsu/vizeq/util/SystemPropertiesProxy.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2013, Haruki Hasegawa - * - * Licensed under the MIT license: - * http://creativecommons.org/licenses/MIT/ - */ - -/** - * from http://stackoverflow.com/questions/2641111/where-is-android-os-systemproperties - */ - -package com.lsu.vizeq.util; - -import java.lang.reflect.Method; - -import android.content.Context; -import android.util.Log; - -public class SystemPropertiesProxy { - private static final String TAG = "SystemPropertiesProxy"; - - /** - * Get the value for the given key, returned as a boolean. Values 'n', 'no', - * '0', 'false' or 'off' are considered false. Values 'y', 'yes', '1', 'true' - * or 'on' are considered true. (case insensitive). If the key does not exist, - * or has any other value, then the default result is returned. - * - * @param key the key to lookup - * @param def a default value to return - * @return the key parsed as a boolean, or def if the key isn't found or is - * not able to be parsed as a boolean. - * @throws IllegalArgumentException if the key exceeds 32 characters - */ - public static Boolean getBoolean(Context context, String key, boolean def) - throws IllegalArgumentException { - return getBoolean(context.getClassLoader(), key, def); - } - - public static Boolean getBoolean(ClassLoader cl, String key, boolean def) - throws IllegalArgumentException { - - Boolean ret = def; - - try { - @SuppressWarnings("rawtypes") - Class SystemProperties = cl.loadClass("android.os.SystemProperties"); - - // Parameters Types - @SuppressWarnings("rawtypes") - Class[] paramTypes = new Class[2]; - paramTypes[0] = String.class; - paramTypes[1] = boolean.class; - - @SuppressWarnings("unchecked") - Method getBoolean = SystemProperties.getMethod("getBoolean", paramTypes); - - // Parameters - Object[] params = new Object[2]; - params[0] = new String(key); - params[1] = Boolean.valueOf(def); - - ret = (Boolean) getBoolean.invoke(SystemProperties, params); - - } catch (IllegalArgumentException iAE) { - throw iAE; - } catch (Exception e) { - Log.e(TAG, "getBoolean(context, key: " + key + ", def:" + def + ")", e); - ret = def; - } - - return ret; - } -} diff --git a/src/com/lsu/vizeq/util/TunnelPlayerWorkaround.java b/src/com/lsu/vizeq/util/TunnelPlayerWorkaround.java deleted file mode 100644 index 6f01f01..0000000 --- a/src/com/lsu/vizeq/util/TunnelPlayerWorkaround.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright 2013, Haruki Hasegawa - * - * Licensed under the MIT license: - * http://creativecommons.org/licenses/MIT/ - */ - -package com.lsu.vizeq.util; - -import java.io.IOException; - -import android.content.Context; -import android.media.AudioManager; -import android.media.MediaPlayer; -import android.util.Log; - -import com.lsu.vizeq.R; - -public class TunnelPlayerWorkaround { - private static final String TAG = "TunnelPlayerWorkaround"; - - private static final String SYSTEM_PROP_TUNNEL_DECODE_ENABLED = "tunnel.decode"; - - private TunnelPlayerWorkaround() - { - } - - /** - * Obtain "tunnel.decode" system property value - * - * @param context Context - * @return Whether tunnel player is enabled - */ - public static boolean isTunnelDecodeEnabled(Context context) - { - return SystemPropertiesProxy.getBoolean( - context, SYSTEM_PROP_TUNNEL_DECODE_ENABLED, false); - } - - /** - * Create silent MediaPlayer instance to avoid tunnel player issue - * - * @param context Context - * @return MediaPlayer instance - */ - public static MediaPlayer createSilentMediaPlayer(Context context) - { - boolean result = false; - - MediaPlayer mp = null; - try { - //mp = MediaPlayer.create(context, R.raw.workaround_1min); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - - // NOTE: start() is no needed - // mp.start(); - - result = true; - } catch (RuntimeException e) { - Log.e(TAG, "createSilentMediaPlayer()", e); - } finally { - if (!result && mp != null) { - try { - mp.release(); - } catch (IllegalStateException e) { - } - } - } - - return mp; - } -}