aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/pheelicks/utils/TunnelPlayerWorkaround.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/pheelicks/utils/TunnelPlayerWorkaround.java')
-rw-r--r--src/com/pheelicks/utils/TunnelPlayerWorkaround.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/com/pheelicks/utils/TunnelPlayerWorkaround.java b/src/com/pheelicks/utils/TunnelPlayerWorkaround.java
new file mode 100644
index 0000000..c25caf0
--- /dev/null
+++ b/src/com/pheelicks/utils/TunnelPlayerWorkaround.java
@@ -0,0 +1,72 @@
+/**
+ * Copyright 2013, Haruki Hasegawa
+ *
+ * Licensed under the MIT license:
+ * http://creativecommons.org/licenses/MIT/
+ */
+
+package com.pheelicks.utils;
+
+import java.io.IOException;
+
+import android.content.Context;
+import android.media.AudioManager;
+import android.media.MediaPlayer;
+import android.util.Log;
+
+import com.pheelicks.visualizer.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;
+ }
+}