Android sound pool function - android

is it possible to check the status of "Sound pool". i want to perform some function when it will start and stop. like ;mediaplayer's function "isplaying() ". is sound pool has this type of functionality...

Unfortunately it looks like the SoundPool API doesn't provide that functionality; it lets you start and stop a sound but doesn't have a method to check its status. In one of my apps I basically hacked around it by maintaining my own boolean that I set true when I started the sound, then set false when I stopped it or enough time had passed.
//your code to start sound here
long soundStartTime = System.currentTimeMillis();
soundPlaying=true;
//other code here
if(System.currentTimeMillis()-soundStartTime > SOUND_LENGTH_MILLIS){
soundPlaying=false;
//also set false at beginning of level and whenever you stop it manually

Refer this code..
SoundPoolManager Class
package com.demosoft.music;
import android.media.SoundPool;
import android.media.JetPlayer;
class SoundPoolEvent
{
public SoundPoolEvent(int eventType,int eventSound)
{
this.eventType = eventType;
this.eventSound = eventSound;
}
public int eventType;
public int eventSound;
public static final int SOUND_PLAY=0;
public static final int SOUND_STOP=1;
public static final int SOUND_MUSIC_PLAY=2;
public static final int SOUND_MUSIC_PAUSE=3;
public static final int SOUND_MUSIC_STOP=4;
public static final int SOUND_MUSIC_RESUME=5;
}
class SoundStatus
{
public SoundStatus()
{
}
public static final int STATUS_LOOPING_NOT_STARTED=0;
public static final int STATUS_LOOPING_PAUSED=1;
public static final int STATUS_LOOPING_PLAYING=2;
}
public class SoundPoolManager implements Sound
{
SoundPoolManager(android.content.Context context)
{
this.context = context;
soundEvents = new java.util.LinkedList();
sounds = new java.util.HashMap();
handles = new java.util.HashMap();
streamIds = new java.util.HashMap();
isRunning = false;
finished = false;
this.musicPlayer =JetPlayer.getJetPlayer();
this.musicPlayer.loadJetFile(context.getResources().openRawResourceFd(R.raw.notify));
byte segmentId = 0;
this.musicPlayer.queueJetSegment(0, -1, -1, 0, 0, segmentId++);
}
public void addSound(int resid, boolean isLooping)
{
sounds.put(resid, new Boolean(isLooping));
}
public void startSound()
{
this.soundPool = new android.media.SoundPool(this.sounds.size(),android.media.AudioManager.STREAM_MUSIC,100);
java.util.Iterator iterator = sounds.keySet().iterator();
while(iterator.hasNext())
{
int soundid = iterator.next().intValue();
int soundhandle = this.soundPool.load(this.context, soundid, 1);
handles.put(new Integer(soundid), new Integer(soundhandle));
}
}
public void stopSound()
{
try
{
java.util.Iterator iterator = sounds.keySet().iterator();
while(iterator.hasNext())
{
int soundid = iterator.next().intValue();
this.soundPool.pause( this.handles.get(soundid).intValue());
this.soundPool.stop(this.handles.get(soundid).intValue());
}
}
catch(Exception e)
{
}
finally
{
try
{
this.musicPlayer.pause();
}
catch(Exception e1)
{
}
try
{
this.musicPlayer.release();
}
catch(Exception e2)
{
}
try
{
this.soundPool.release();
}
catch(Exception e3)
{
}
}
}
public int currentPlayer;
private boolean isRunning;
private java.util.HashMap sounds;
private java.util.HashMap handles;
private java.util.HashMap streamIds;
private android.content.Context context;
private java.util.LinkedList soundEvents;
private java.util.HashMap mediaPlayers;
public void stopSound(int resid)
{
}
public void playSound(int resid)
{
if(soundEvents!=null)
{
try
{
android.media.AudioManager mgr = (android.media.AudioManager) context.getSystemService(android.content.Context.AUDIO_SERVICE);
int streamVolume = mgr.getStreamVolume(android.media.AudioManager.STREAM_MUSIC);
int streamID = soundPool.play(handles.get( resid).intValue(), streamVolume, streamVolume, 1, 0, 1.0f);
int maxvolume = mgr.getStreamMaxVolume(android.media.AudioManager.STREAM_MUSIC);
mgr.setStreamVolume(android.media.AudioManager.STREAM_MUSIC, maxvolume, 0);
this.streamIds.put(resid, streamID);
}
catch(Exception e)
{
}
}
}
public void startMusic(int resid)
{
this.musicPlayer.play();
}
public void stopMusic(int resid)
{
this.musicPlayer.pause();
}
public void pauseMusic(int resid)
{
this.musicPlayer.pause();
}
public void resumeMusic(int resid)
{
this.musicPlayer.play();
}
SoundPool soundPool;
JetPlayer musicPlayer;
boolean finished = false;
}
And add the interface of Sound..... to the above package
package com.demosoft.music;
public interface Sound {
public void addSound(int resid, boolean isLooping);
public void startSound();
public void stopSound();
public void stopSound(int resid);
public void playSound(int resid);
public void startMusic(int resid);
public void stopMusic(int resid);
public void pauseMusic(int resid);
public void resumeMusic(int resid);
}
And u can use in difffernt ways ....
1. creating the soundpoolmanager instance class ......
2. by using Sound interface instance,....
SoundPoolManager m = new SoundPoolManager(context);
m.addSound(R.raw.demo, false);
m.addSound(R.raw.soft,true);
m.startSound();
m.playSound(R.raw.demo);
m.playMusic(R.raw.soft);
or
private Sound soundManager;
soundManager.playSound(R.raw.demo);
public synchronized void stopMusic()
{
soundManager.stopSound();
//message.sendToTarget();
this.soundManager.stopSound();
}

Related

How to get user ID or info in onAuthenticationSucceeded method for android fingerprint

I am implementing an android fingerprint authentication. I want to know which user, who has registered in device before, is authenticating. Is there any information about the user, who has registered and is valid for the device, in the FingerprintManager.AuthenticationResult argument in onAuthenticationSucceeded method?!
I am using this sample.
this is my class, which is implementing FingerprintManager.AuthenticationCallback:
public class FingerprintUiHelper extends FingerprintManager.AuthenticationCallback {
private static final long ERROR_TIMEOUT_MILLIS = 1600;
private static final long SUCCESS_DELAY_MILLIS = 1300;
private final FingerprintManager mFingerprintManager;
private final ImageView mIcon;
private final TextView mErrorTextView;
private final Callback mCallback;
private CancellationSignal mCancellationSignal;
private boolean mSelfCancelled;
/**
* Constructor for {#link FingerprintUiHelper}.
*/
FingerprintUiHelper(FingerprintManager fingerprintManager,
ImageView icon, TextView errorTextView, Callback callback) {
mFingerprintManager = fingerprintManager;
mIcon = icon;
mErrorTextView = errorTextView;
mCallback = callback;
}
public boolean isFingerprintAuthAvailable() {
// The line below prevents the false positive inspection from Android Studio
// noinspection ResourceType
return mFingerprintManager.isHardwareDetected()
&& mFingerprintManager.hasEnrolledFingerprints();
}
public void startListening(FingerprintManager.CryptoObject cryptoObject) {
if (!isFingerprintAuthAvailable()) {
return;
}
mCancellationSignal = new CancellationSignal();
mSelfCancelled = false;
// The line below prevents the false positive inspection from Android Studio
// noinspection ResourceType
mFingerprintManager
.authenticate(cryptoObject, mCancellationSignal, 0 /* flags */, this, null);
mIcon.setImageResource(R.drawable.ic_fp_40px);
}
public void stopListening() {
if (mCancellationSignal != null) {
mSelfCancelled = true;
mCancellationSignal.cancel();
mCancellationSignal = null;
}
}
#Override
public void onAuthenticationError(int errMsgId, CharSequence errString) {
if (!mSelfCancelled) {
showError(errString);
mIcon.postDelayed(new Runnable() {
#Override
public void run() {
mCallback.onError();
}
}, ERROR_TIMEOUT_MILLIS);
}
}
#Override
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
showError(helpString);
}
#Override
public void onAuthenticationFailed() {
showError(mIcon.getResources().getString(
R.string.fingerprint_not_recognized));
}
#Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
mIcon.setImageResource(R.drawable.ic_fingerprint_success);
mErrorTextView.setTextColor(
mErrorTextView.getResources().getColor(R.color.success_color, null));
mErrorTextView.setText(
mErrorTextView.getResources().getString(R.string.fingerprint_success));
mIcon.postDelayed(new Runnable() {
#Override
public void run() {
mCallback.onAuthenticated();
}
}, SUCCESS_DELAY_MILLIS);
}
private void showError(CharSequence error) {
mIcon.setImageResource(R.drawable.ic_fingerprint_error);
mErrorTextView.setText(error);
mErrorTextView.setTextColor(
mErrorTextView.getResources().getColor(R.color.warning_color, null));
mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
mErrorTextView.postDelayed(mResetErrorTextRunnable, ERROR_TIMEOUT_MILLIS);
}
private Runnable mResetErrorTextRunnable = new Runnable() {
#Override
public void run() {
mErrorTextView.setTextColor(
mErrorTextView.getResources().getColor(R.color.hint_color, null));
mErrorTextView.setText(
mErrorTextView.getResources().getString(R.string.fingerprint_hint));
mIcon.setImageResource(R.drawable.ic_fp_40px);
}
};
public interface Callback {
void onAuthenticated();
void onError();
}
}

Android PreferenceManager.setDefaultValues() crashes with class cast exception

I have a frustrating problem, I have created a custom preference for Android, using the support library.
public class CustomTimePreference extends DialogPreference {
public int hour = 0;
public int minute = 0;
public CustomTimePreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public static int parseHour(String value) {
try {
String[] time = value.split(":");
return (Integer.parseInt(time[0]));
} catch (Exception e) {
return 0;
}
}
public static int parseMinute(String value) {
try {
String[] time = value.split(":");
return (Integer.parseInt(time[1]));
} catch (Exception e) {
return 0;
}
}
public static String timeToString(int h, int m) {
return String.format("%02d", h) + ":" + String.format("%02d", m);
}
#Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return a.getString(index);
}
#Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
String value;
if (restoreValue) {
if (defaultValue == null) value = getPersistedString("00:00");
else value = getPersistedString(defaultValue.toString());
} else {
value = defaultValue.toString();
}
hour = parseHour(value);
minute = parseMinute(value);
}
public void persistStringValue(String value) {
persistString(value);
}
}
and
public class CustomTimePreferenceDialogFragmentCompat extends PreferenceDialogFragmentCompat implements DialogPreference.TargetFragment {
TimePicker timePicker = null;
#Override
protected View onCreateDialogView(Context context) {
timePicker = new TimePicker(context);
return (timePicker);
}
#Override
protected void onBindDialogView(View v) {
super.onBindDialogView(v);
timePicker.setIs24HourView(true);
CustomTimePreference pref = (CustomTimePreference) getPreference();
timePicker.setCurrentHour(pref.hour);
timePicker.setCurrentMinute(pref.minute);
}
#Override
public void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
CustomTimePreference pref = (CustomTimePreference) getPreference();
pref.hour = timePicker.getCurrentHour();
pref.minute = timePicker.getCurrentMinute();
String value = CustomTimePreference.timeToString(pref.hour, pref.minute);
if (pref.callChangeListener(value)) pref.persistStringValue(value);
}
}
#Override
public Preference findPreference(CharSequence charSequence) {
return getPreference();
}
}
For completeness, the xml contained within the preferences.xml is:
<customcontrols.CustomTimePreference
android:key="time_pace_preference"
android:title="#string/title_time_pace_preference"
android:defaultValue="#string/settings_default_pace"
android:summary="Set some time"
/>
However, when I attempt to call
PreferenceManager.setDefaultValues(mContext, preferences, true);
I receive
java.lang.ClassCastException: customcontrols.CustomTimePreference cannot be cast to android.preference.Preference
Why is this happening? as CustomTimePreference extends DialogPreference which itself extends Preference, this should be fine?!
If I don't call the setDefaultValues() I am able to go into my settings fragment and view the custom control?
What am I doing wrong, and how do I fix it!?
If you are extending android.support.v7.preference.DialogPreference that will cause this crash.
If so, you can use android.support.v7.preference.PreferenceManager#setDefaultValues(android.content.Context, int, boolean) instead.

AndroidStudio 2.0 preview generated APK shows error on Dalvik

from AudioPlayService class onCreate() i call following code on line 168.-
line168- CustomAuxEffectStats aa = CustomAuxEffectStats.getInstance();
if (aa == null) {
createCustomAuxEffect();
}
CustomAuxEffectStats class-
public class CustomAuxEffectStats implements Serializable {
private static CustomAuxEffectStats customAuxEffectStats = null;
public static int CustomPresetID = -100;
public static final int DEFAULT_BASS_BOOST_STRENGTH = 900;
private boolean isEnabled;
private int numBands;
private int actualNumPreset;
private short selectedPreset;
private short minBandLevel;
private short maxBandLevel;
private short bassboostStrength;
private short[] bandLevels;
private String[] bandFreq;
private String[] presetNames;
private CustomAuxEffectStats(short curPreset, String[] presetNamesArr, String[] bandFreqs, short[] bandLevelRange, short[] bandlevels, boolean isEnabled) {
this.isEnabled = isEnabled;
selectedPreset = curPreset;
minBandLevel = bandLevelRange[0];
maxBandLevel = bandLevelRange[1];
numBands = bandlevels.length;
bandFreq = bandFreqs;
actualNumPreset = presetNamesArr.length - 1;
CustomPresetID = presetNamesArr.length;
presetNames = presetNamesArr;
this.bandLevels = bandlevels;
bassboostStrength = 1000;
}
public static CustomAuxEffectStats getInstance() {
return customAuxEffectStats;
}
public static CustomAuxEffectStats createInstance(short curPreset, String[] presetNamesArr, String[] bandFreqs, short[] bandLevelRange, short[] bandlevels, boolean isEnabled) {
if (customAuxEffectStats == null) {
customAuxEffectStats = new CustomAuxEffectStats(curPreset, presetNamesArr, bandFreqs, bandLevelRange, bandlevels, isEnabled);
}
return customAuxEffectStats;
}
public boolean isEnabled() {
return isEnabled;
}
public void setEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}
public int getNumBands() {
return numBands;
}
public void setNumBands(int numBands) {
this.numBands = numBands;
}
public short getSelectedPreset() {
return selectedPreset;
}
public void setSelectedPreset(short selectedPreset) {
this.selectedPreset = selectedPreset;
}
public short getMinBandLevel() {
return minBandLevel;
}
public void setMinBandLevel(short minBandLevel) {
this.minBandLevel = minBandLevel;
}
public short getMaxBandLevel() {
return maxBandLevel;
}
public void setMaxBandLevel(short maxBandLevel) {
this.maxBandLevel = maxBandLevel;
}
public short[] getBandLevels() {
return bandLevels;
}
public void setBandLevels(short[] bandLevels) {
this.bandLevels = bandLevels;
}
public String[] getBandFreq() {
return bandFreq;
}
public void setBandFreq(String[] bandFreq) {
this.bandFreq = bandFreq;
}
public static int getCustompresetid() {
return CustomPresetID;
}
public short getBassBoostStrength() {
return bassboostStrength;
}
public void setBandLevel(short band, short progress) {
bandLevels[band] = progress;
}
public short getbandLevel(short band) {
return bandLevels[band];
}
public int getNumberOfPresets() {
return actualNumPreset;
}
public String[] getPresetNames() {
return presetNames;
}
public void setPresetNames(String[] presetNames) {
this.presetNames = presetNames;
}
public void setBassboostStrength(short bassboostStrength) {
this.bassboostStrength = bassboostStrength;
}
}
this always crashes on kitkat(dalvik run time) device when i run my app.
but it works fine in L+(ART) devices and emulators.
error log-
FATAL EXCEPTION: main
Process: com.newwave.musicsquare, PID: 26143
java.lang.VerifyError: com/newwave/musicsquare/audio/data/CustomAuxEffectStats
at com.newwave.musicsquare.services.AudioPlayService.onCreate(AudioPlayService.java:168)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2574)
at android.app.ActivityThread.access$1800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
So i figured it out..
As i was maintaining this legacy project..
the serialized class CustomAuxEffectStats had a lot of arguments in constructor that were causing problem and a lot of getters, setters...
i removed the methods and made all the fields class level.
removed all arguments from constructor...
everything is working fine.

Playing HLS with ExoPlayer

I'm trying to create a very simple view by extending SurfaceView and rendering the ExoPlayer video to the its surface. I want to support HLS and ONLY HLS. I seem to get audio consistently but I never see video rendered to the screen. I'm curious as to what I could be doing wrong.
The only error that I am seeing in my Logcat is the following:
E/OMXMaster﹕ A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one.
Below is my code.
private static final int BUFFER_SEGMENT_SIZE = 256 * 1024;
private static final int BUFFER_SEGMENTS = 64;
private ExoPlayer mExoPlayer;
private Handler mHandler;
private AudioCapabilitiesReceiver mAudioCapabilitiesReceiver;
private AudioCapabilities mAudioCapabilities;
private ManifestFetcher<HlsPlaylist> playlistFetcher;
private String mUserAgent;
String url = "http://solutions.brightcove.com/bcls/assets/videos/Great-Blue-Heron.m3u8";
public ExoPlayerView(Context context) {
super(context);
}
public ExoPlayerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExoPlayerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public void init() {
mHandler = new Handler();
mUserAgent = Util.getUserAgent(getContext(), "CX Video Player");
HlsPlaylistParser parser = new HlsPlaylistParser();
playlistFetcher = new ManifestFetcher<>(url, new DefaultUriDataSource(getContext(), mUserAgent),
parser);
mAudioCapabilitiesReceiver = new AudioCapabilitiesReceiver(getContext(), this);
mAudioCapabilitiesReceiver.register();
}
#Override
public void play() {
mExoPlayer.setPlayWhenReady(true);
}
#Override
public void stop() {
mExoPlayer.stop();
release();
}
#Override
public void pause() {
mExoPlayer.setPlayWhenReady(false);
}
#Override
public void seekTo(long timeMillis) {
mExoPlayer.seekTo(timeMillis);
}
#Override
public long getCurrentPosition() {
return mExoPlayer.getCurrentPosition();
}
#Override
public boolean isPlaying() {
return false;
}
#Override
public void playNext() {
}
#Override
public boolean isPlayingLastVideo() {
return false;
}
#Override
public int getDuration() {
return (int)mExoPlayer.getDuration();
}
#Override
public void addVideo(Uri uri) {
}
#Override
public void addVideos(List<Uri> uris) {
}
#Override
public void release() {
mAudioCapabilitiesReceiver.unregister();
mExoPlayer.release();
}
#Override
public void onSingleManifest(HlsPlaylist hlsPlaylist) {
final int numRenderers = 2;
LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
int[] variantIndices = null;
if (hlsPlaylist instanceof HlsMasterPlaylist) {
HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) hlsPlaylist;
try {
variantIndices = VideoFormatSelectorUtil.selectVideoFormatsForDefaultDisplay(
getContext(), masterPlaylist.variants, null, false);
} catch (MediaCodecUtil.DecoderQueryException e) {
e.printStackTrace();
return;
}
if (variantIndices.length == 0) {
return;
}
}
DataSource dataSource = new DefaultUriDataSource(getContext(), bandwidthMeter, mUserAgent);
HlsChunkSource hlsChunkSource = new HlsChunkSource(dataSource, url, hlsPlaylist, bandwidthMeter,
variantIndices, HlsChunkSource.ADAPTIVE_MODE_SPLICE, mAudioCapabilities);
HlsSampleSource hlsSampleSource = new HlsSampleSource(hlsChunkSource, loadControl, BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE);
// Build the track renderers
TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(hlsSampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(hlsSampleSource);
// Build the ExoPlayer and start playback
mExoPlayer = ExoPlayer.Factory.newInstance(numRenderers);
mExoPlayer.prepare(videoRenderer, audioRenderer);
// Pass the surface to the video renderer.
mExoPlayer.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, getHolder().getSurface());
mExoPlayer.setPlayWhenReady(true);
}
#Override
public void onSingleManifestError(IOException e) {
}
#Override
public void onAudioCapabilitiesChanged(AudioCapabilities audioCapabilities) {
mAudioCapabilities = audioCapabilities;
playlistFetcher.singleLoad(mHandler.getLooper(), this);
}
}
So I found my issue. After going back through the demo code, I noticed that the demo SurfaceView was wrapped in com.google.android.exoplayer.AspectRatioFrameLayout. After wrapping my SurfaceView in this same layout, the video magically started playing.
I had a similar situation where i could hear the audio but no video, just a black screen. Turns out i was trying to send the set surface mesagge:
player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
before the video render was actually initialised and ready which is why i could hear audio only

I dont know how to change ok glass phrase in google glass

I want to make glass application with offline voice recognition with no ok glass
what I want to know is changing ok glass to other words ( something like "start").
I saw the source decompiled GlassHome.apk and GlassVoice.apk.
I knew that setting to ok glass is related with VoiceInputHelper, voice_label_ok_glass in String.xml
so I tried to change all of string "ok glass" to "nice"(temp guard phrase) in String.xml
but when I said any word (like "hahaha" or "kakaka") , all of word I said is recognized to my guard phrase ("nice") by VoiceService.
what should I do for changing "ok glass" to my guard phrase and working it right ???????
(P.S sorry my bad english. I hope you understand what question means)
here is my code ( I tried to set VoiceConfig to "nice")
public class MainActivity extends GlassActivity implements VoiceListener {
public static final String TEST_SERVICE_EXTRAS_KEY = "serviceExtras";
private ImageView gradientView;
private GuardHintAnimator guardHintAnimator;
private TextView guardPhraseView;
private boolean isRunning = false;
private final FormattingLogger logger = FormattingLoggers.getLogger(this);
private VoiceConfig onWindowFocusChangedRecoverConfig;
private VoiceConfig voiceConfig;
#VisibleForTesting
VoiceInputHelper voiceInputHelper;
private IVoiceMenuDialog voiceMenuDialog;
public FormattingLogger getLogger()
{
return this.logger;
}
public boolean isRunning()
{
return this.isRunning;
}
#Override
protected void onCreateInternal(Bundle bundle) {
super.onCreateInternal(bundle);
this.voiceInputHelper = new VoiceInputHelper(this, new DelegatingVoiceListener(this)
{
public VoiceConfig onVoiceCommand(VoiceCommand paramAnonymousVoiceCommand)
{
if ((!MainActivity.this.hasWindowFocus()) && (!MainActivity.this.isMessageShowing()))
{
MainActivity.this.logger.d("Ignoring voice command because we don't have window focus.", new Object[0]);
return null;
}
Log.d("listener",paramAnonymousVoiceCommand.toString());
//return super.onVoiceCommand(paramAnonymousVoiceCommand);
return null;
}
}, getVoiceServiceExtras());
}
protected void onPauseInternal()
{
this.isRunning = false;
super.onPauseInternal();
closeVoiceMenu();
this.voiceInputHelper.setVoiceConfig(VoiceConfig.OFF);
this.voiceInputHelper.unregisterGrammarLoaders();
}
public void closeVoiceMenu()
{
if (this.voiceMenuDialog != null)
{
this.voiceMenuDialog.dismiss(false);
this.voiceMenuDialog = null;
}
}
public void onPrepareVoiceMenu(VoiceMenuDialog paramVoiceMenuDialog) {}
public boolean onResampledAudioData(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
{
return false;
}
protected void onResumeInternal()
{
this.isRunning = true;
super.onResumeInternal();
this.voiceInputHelper.registerGrammarLoaders();
this.voiceInputHelper.setWantAudioData(shouldProvideAudioData());
NetworkUtil.checkNetwork();
VoiceConfig localVoiceConfig = new VoiceConfig();
String[] arrayOfString = new String[1];
arrayOfString[0] = "nice";
localVoiceConfig = localVoiceConfig.setCustomPhrases(arrayOfString).setShouldSaveAudio(true);
voiceInputHelper.setVoiceConfig(localVoiceConfig);
}
public boolean isVoiceMenuShowing()
{
return (this.voiceMenuDialog != null) && (this.voiceMenuDialog.isShowing());
}
public VoiceConfig onVoiceCommand(VoiceCommand paramVoiceCommand)
{
Log.d("hhh",paramVoiceCommand.toString());
this.logger.w("Unrecognized voice command: %s", new Object[] { paramVoiceCommand });
return null;
}
protected Bundle getVoiceServiceExtras()
{
Bundle localBundle = new Bundle();
/* if (getIntent().hasExtra("serviceExtras"))
{
localBundle.putAll(getIntent().getBundleExtra("serviceExtras"));
}*/
return localBundle;
}
public void setVoiceConfig(VoiceConfig paramVoiceConfig)
{
this.voiceConfig = paramVoiceConfig;
if (paramVoiceConfig != null) {
this.voiceInputHelper.setVoiceConfig(this.voiceConfig);
}
}
public boolean shouldProvideAudioData()
{
return false;
}
public void onVoiceConfigChanged(VoiceConfig paramVoiceConfig, boolean paramBoolean) {}
}
DelegatingVoiceListener :
class DelegatingVoiceListener implements VoiceListener
{
private final VoiceListener delegate;
DelegatingVoiceListener(VoiceListener paramVoiceListener)
{
this.delegate = paramVoiceListener;
}
public FormattingLogger getLogger()
{
return this.delegate.getLogger();
}
public boolean isRunning()
{
return this.delegate.isRunning();
}
public boolean onResampledAudioData(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
{
return this.delegate.onResampledAudioData(paramArrayOfByte, paramInt1, paramInt2);
}
public VoiceConfig onVoiceCommand(VoiceCommand paramVoiceCommand)
{
return this.delegate.onVoiceCommand(paramVoiceCommand);
}
public void onVoiceConfigChanged(VoiceConfig paramVoiceConfig, boolean paramBoolean)
{
this.delegate.onVoiceConfigChanged(paramVoiceConfig, paramBoolean);
}
}
You need to request special permissions in your manifest to implement unlisted voice commands. Go here. However, I doubt you can change the 'ok glass' voice command. You can still try if you really want to.

Categories

Resources