Equalizer UnsupportedOperationException: AudioEffect: invalid parameter operation - java

This is my equalizer class, and for a long time it worked without any problem,but now i'm getting this error.
P.S yesterday i flashed a custom rom on my phone, could that be the problem?
Because on another device it works fine.
Error
Caused by: java.lang.UnsupportedOperationException: AudioEffect: invalid parameter operation
at android.media.audiofx.AudioEffect.checkStatus(AudioEffect.java:1299)
at android.media.audiofx.Equalizer.setBandLevel(Equalizer.java:223)
My code
verticalSeekbar[i].setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
short newLevel = (short)(progress + lowerEqualizerBandLevel);
short band = (short)seekBar.getTag();
bandLevels[band] = newLevel;
if (mEqualizer != null) {
mEqualizer.setBandLevel(band, newLevel);
}
slider_value[band].setText((progress + lowerEqualizerBandLevel) / 100 + " dB");
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
slider_labels[i].setText(formatBandLabel(freq_range));
}
EDIT
Im certain that the problem is the custom rom because on stock roms it works fine.
What could be the reason it throws UnsupportedOperationException on custom roms?

Related

How can I use 2 threads at the same time for bluetooth connection

I'm having some issues to make work a code i took from a tutorial :
https://developer.android.com/guide/topics/connectivity/bluetooth/transfer-data
I tried connecting this way :
_spinnerBT_Devices.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView adapterView, View view, int i, long l) {
_Selected_Device = (BluetoothDevice) _BT_Devices_list.get(i);
_printf.setText(_Selected_Device.getName());
_myThread = new ConnectThread(_Selected_Device);
_myThread.run();
_myService = new MyBluetoothService.ConnectedThread(_myThread.mmSocket);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
//_myThread.cancel();
}
});
And write on my serial bluetooth :
public void buttonUpClick() {
_buttonUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
_printf.setText("Debug : UP");
if(_myService.mmSocket.isConnected()){
_myService.write("z".getBytes(StandardCharsets.UTF_8));
}
}
});
}
But as soon as I try to write on it, the app crashes, like it can't use two threads at the same time.
edit : I can write but only one time and it crashes
Found the problem
It wasn't about having 2 threads but the code was crashing cause of that part :
// Share the sent message with the UI activity.
Message writtenMsg = handler.obtainMessage(
MessageConstants.MESSAGE_WRITE, -1, -1, mmBuffer);
writtenMsg.sendToTarget();

How to constantly update a Text View

I'm trying out making an app using Android Studio and I want to constantly update a text view.
I at first thought I should use a loop but that ended up not even running for some reason.
TextView amount = findViewById(R.id.amountTextView);
final SeekBar seekBar = findViewById(R.id.seekBar);
int p = seekBar.getProgress() + 1;
amount.setText(String.valueOf(p));
});
}
}
With this method it doesn't update the results text view. I would like it to constantly update the text view so it shows what number the seek bar is on.
You will need an event for update the state of SeekBar and TextView, in this case I user a Handler(android.os) for update the views each 100 milliseconds of time, but you can use another event like the load of a web service or another.
In your case, it doesn't update because you just update the state of variable, but never update the state of seekbar, that is the reason it will never increment the current state.
private void startLoopUntilEnd() {
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
#Override
public void run() {
int progress = seekBar.getProgress();
textView.setText(String.valueOf(progress));
progress++;
seekBar.setProgress(progress);
startLoopUntilEnd();
}
};
if (currentState <seekBar.getMax()){
handler.postDelayed(runnable,100);
}
}
You can call this method from onCreate in case of Activity or onResume in case of Fragment and after it will go until the SeekBar is complete recursively.
If you want to change the max of seekBar, you can set it in xml or in code.
Use onSeekBarChangeListener:
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
amount.setTextprogress);
}
});

How to implement Reward video with Startapp

Recently I'm facing issue related to Startapp platform for Android.
When I implemented the reward video it returns an error with:
FailledError execute Exception Error sendGetWithResponse code = [204]
Here is my function:
public void rewardAd() {
Log.i("TAG", "Test");
startAppAd.setVideoListener(new VideoListener() {
#Override
public void onVideoCompleted() {
Log.i("TAG", "Grant User");
}
});
startAppAd.loadAd(StartAppAd.AdMode.REWARDED_VIDEO, new AdEventListener() {
#Override
public void onReceiveAd(com.startapp.android.publish.adsCommon.Ad ad) {
startAppAd.showAd();
}
#Override
public void onFailedToReceiveAd(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "Failled"+ ad.getErrorMessage());
startAppAd.showAd(new AdDisplayListener() {
#Override
public void adHidden(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "adHidden");
}
#Override
public void adDisplayed(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "adDisplayed");
}
#Override
public void adClicked(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "adClicked");
}
#Override
public void adNotDisplayed(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "adNotDisplayed"+ ad.getErrorMessage());
}
});
//startAppAd.showAd(getApplicationContext());
}
});
}
Here is the logs that shows:
TAG: Test
TAG: FailledError execute Exception Error sendGetWithResponse code = [204]
TAG: adNotDisplayed
When I comment the function startAppAd.showAd(), and uncomment the last commented one startAppAd.showAd(), it's working fine.
This is the expected working scheme:
Try to load a Video Reward Ad => startAppAd.loadAd();
if failed (like my case) => onFailedToReceiveAd();
Try to show an Ad that I can get listeners of it => startAppAd.showAd()
Thank You very much
It's solved, the script itself is not bad and works fine, the problem was with Startapp they don't show a video ad because it doesn't exist any video to show.
Now if someone is facing the same problem i suggest to use a vpn on testing device with a country that startapp should have a video ad usually US.

Updating Seekbar after changing Edittext

So I've got a seekbar and an edittext. My aim is to type in a number in the edittext, and in the same time the seekbar should jump to the related position. This should also work vise versa.
I've already got the code for them seperately. But something is missing. Because when I put in both and start then i can slide the seekbar and the value is changing in the same time in the edittext. But when i try to type in a number, it jumps to the beginning. Example: i want to type 123...result is 321. more or less the same with deleting.
I think the two codes are crashing each other, bit i don't know what to change.
And maybe i should say that i'm new in this field.
I'm not sure if my intentions are understandable..
Here my codes:
1.
value.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int after, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
try{
//Update Seekbar value after entering a number
int progress = Math.round(Float.parseFloat(s.toString()));
seekbar.setProgress(progress);
value.setText(value.getText().length());
} catch(Exception ex) {}
}
});
2.
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
value.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
As you see, there is a parameter passed into "onProgressChanged" function called "fromUser":
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
It defines that progress is changed by "physically" shfting the slider, so all You have to do, is just type as below:
if (fromUser) value.setText(String.valueOf(progress));
It prevents doing this kind of loop.
value.setText(value.getText().length());
This line is called first, changing the text.
value.setText(String.valueOf(progress));
Then this line is called, changing the text to something else. These 2 setText()'s happen so fast, you cannot see that it happened twice, you only see the result of the last one.
I propose you remove the value.setText(value.getText().length());, displaying the length of the value string is not something you want to do, if I understand your question correctly.
The problem is in your afterTextChanged() method.
1. Remove line value.setText(value.getText().length()); from afterTextChanged().
value.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence charSequence, int after, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
try {
int progress = Math.round(Float.parseFloat(s.toString()));
seekBar.setProgress(progress);
} catch (Exception e) {}
}
});
2. Update onProgressChanged() method as below, to move cursor position as per text change.
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
value.setText(String.valueOf(progress));
value.setSelection(String.valueOf(progress).length());
}
OUTPUT:
Hope this will help~
value.setText(value.getText().length()); is not using to display the length. It is used to place the cursor position at the end of edittext instead of going it to start position

Method onStartTrackingTouch and getProgress() of seekbar. First value is always 0.

For a lock/unlock system I use the onStartTrackingTouch and onStopTrackingTouch methods. And testing, I don't understand one thing:
public void onStartTrackingTouch(SeekBar seekBar) {
Log.d(TAG,"Progress: "+seekBar.getProgress());
}
The first value is always zero.
Why? I need the real value!
Can anybody help me?
Thanks in advance.
I've changed my idea, finally i've used onProgressChanged:
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if(progress>95){
seekBar.setVisibility(SeekBar.INVISIBLE);
//code
}
public void onStopTrackingTouch(SeekBar seekBar) {
seekBar.setProgress(0);
}
Thanks

Categories

Resources