crash log: InternalError in MediaPlayer.setSubtitleAnchor - java

Seeing the following crash log pop up quite often:
java.lang.InternalError:
at java.lang.Thread.nativeCreate (Native Method)
at java.lang.Thread.start (Thread.java:733)
at android.media.MediaPlayer.setSubtitleAnchor (MediaPlayer.java:3039)
at android.media.MediaPlayer.scanInternalSubtitleTracks (MediaPlayer.java:3240)
at android.media.MediaPlayer.prepare (MediaPlayer.java:1442)
at android.media.MediaPlayer.create (MediaPlayer.java:1046)
at android.media.MediaPlayer.create (MediaPlayer.java:1012)
...
I call MediaPlayer.create with the context/resource parameters. It works fine for me and for 95% of users. One thing to note is that I do get the dreaded
E/MediaPlayer: Should have subtitle controller already set
log message which is the topic of many, many StackOverflow questions. I currently have been ignoring it like most answers tell me to - but if scanInternalSubtitleTracks is creating InternalError crashes, maybe I shouldn't?

in the media Player android after MEDIA_PREPARED, Player start search subtitle and any Exception happen during searching subtitle send instead of crashing.
you should ignore it or you can use another player like ExoPlayer.
case MEDIA_PREPARED:
try {
scanInternalSubtitleTracks();
} catch (RuntimeException e) {
// send error message instead of crashing;
// send error message instead of inlining a call to onError
// to avoid code duplication.
Message msg2 = obtainMessage(
MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, MEDIA_ERROR_UNSUPPORTED, null);
sendMessage(msg2);
}
OnPreparedListener onPreparedListener = mOnPreparedListener;
if (onPreparedListener != null)
onPreparedListener.onPrepared(mMediaPlayer);
return;
in android version 28 android let you use .setOnSubtitleDataListener() that could solve your problem on android 28

Related

SpeechRecognizer.startListening not working on Chromebook 10 but works on Pixel 2XL

I have voice recognition code that crashes upon launch (after the splashscreen). My app works great without voice recognition, but it is required for this app that I have it.
This Acer Chromebook 10 outside of my development has no issue with voice recognition (Okay Google, what time is it... etc.)
Here is a partial screenshot of the error I am getting from logcat on the Chromebook:
I have added permissions in the manifest (before I added this it worked on the Pixel 2XL):
<addPermission android:name="android.permission.BIND_VOICE_INTERACTION"/>
... but still get the same error. I am not launching a competing service, but rather a thread runnable activity. Here is a snippet of the code that I think that may be throwing this error (it crashes right after the splash screen so I don't even get the catch response):
try
{
_activity.runOnUiThread(new Runnable()
{
public void run()
{
// I don't know why, but we have to destroy and redo the recognizer after a failure (unlike onResult), then works great.
mSpeechRecognizer.destroy();
mSpeechRecognizer.setRecognitionListener(recognitionListener);
mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
}
});
} // end of try
catch (Exception e)
{
Log.debug("Recognition failed with exception " + e.getMessage());
}
Some background - like the title says this code is working with Pixel 2XL. It is part of an in-house plugin that I've written for the Unreal Engine to support voice recognition. As such I test for the permission "android.permission.BIND_VOICE_INTERACTION" in Blueprints (a flowchart-like language for UE4) when running the code on my Pixel and it comes back true - so I know this permission is okay with the Pixel 2XL.
I get the impression that there may be a competing service causing conflict on the Chromebook specifically (ArcVoiceInteractionService?) and if this is so, I need to find out how to get around it.

Android: ParseUser.getCurrentUser() returning empty object even after Logout

In my Android code i am checking the condition on parse current user. if user is logged in them some action is performing and if not other action is performing. but when i am checking the condition even after user is logged out the ParseUser.getCurrentUser() is returning object, when i am trying to access data via parseCurrentUserObject the app is crashing, getting either NullpointerException or IllegalStateException.
i also gone through the link Parse for Android : ParseUser.logOut() doesn't log user out
but din't workout for me.
code is -
`
ParseUser.logOut();
if (ParseUser.getCurrentUser() != null) {
Log.d("userType: ", ParseUser.getCurrentUser().getString("userType")
.toString());
tabSettingForPrivateUser(rootView);
} else {
tabSettingForPublicUser(rootView);
}
`
app is crashing at log message where i am trying to access data from object:
Log.d("userType: ", ParseUser.getCurrentUser().getString("userType").toString());
LogCat error message at this line -
08-15 17:58:05.250: E/AndroidRuntime(1220): Caused by: java.lang.NullPointerException
How to deal with this problem ?
The documentation very clearly says:
public static void logOut()
Logs out the currently logged in user
session. This will remove the session from disk, log out of linked
services, and future calls to ParseUser.getCurrentUser() will return
null.
If the method call to ParseUser.getCurrentUser() does not behave as expected, then this is a bug in the API.
Have you tried using the debugger and setting a breakpoint to see what variables are null when your app crashes? Are you sure that the String you are getting isn't null?
Also, you are using a key to access the value in the ParseObject. It is definitely a good idea to keep the keys centralized in an interface. Makes debugging a lot easier and the code more maintainable. Writing the raw string value for the key is definitely a recipe for disaster.

No intent from UserRecoverableAuthIOException using Drive SDK for Android

I've implemented google drive into my android application and it work pretty nice, but I'm trying to figure out a way to run an upload/download in a background thread so that I can leave an activity and do something else on my app. The problem is, drive needs the activity reference in case of exceptions, such as UserRecoverableAuthIOException.
Here's the issue I cannot understand. Here's some try/catch code:
try {
//...drive api stuff here
} catch (UserRecoverableAuthIOException e) {
possibleException = e;
try {
e.getIntent();
} catch ( NullPointerException e2 ) { //this is the crazy part
// e.getIntent() should not throw a nullpointer
e2.printStackTrace();
possibleException = e2;
}
onActivityRestartWhat = RESTART_IMPORT;
// just a note i do handle this exception properly in another section of a code when there is an intent.
} catch (FileNotFoundException e) {
possibleException = e;
e.printStackTrace();
} catch (IOException e) {
possibleException = e;
e.printStackTrace();
}
What I can't figure out is why UserRecoverableAuthIOException is throwing a NullPointerException whey I try to access getIntent.
More Info
I do catch UserRecoverableAuthIOException when more authentication is needed and request it via the startActivityForResult method. Also, this exception is thrown only if I back out of the activity that has started, aka destroy the activity. Basically, I have a process that uploads/downloads drive files in a thread and if I don't leave the activity until completion it works, if I destroy the activity via the back button then I get this exception.
Stack Trace
07-10 14:45:32.903: W/System.err(1450): java.lang.NullPointerException
07-10 14:45:32.913: W/System.err(1450): at android.content.Intent.<init> (Intent.java:3529)
07-10 14:45:32.913: W/System.err(1450): at com.google.android.gms.auth.UserRecoverableAuthException.getIntent(Unknown Source)
07-10 14:45:32.913: W/System.err(1450): at com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException.getIntent(UserRecoverableAuthIOException.java:62)
07-10 14:45:32.913: W/System.err(1450): at my.app.DriveHelper$2.run(DriveHelper.java:211)
My Desire
I want to run downloads/uploads (via google drive) in a background thread. Since the sdk requires startActivityForResult and other methods that might require a reference to an Activity or Context that makes this difficult, but it should work once the app has been granted the sdk permissions that require those references. Hopefully this makes sense.
Below are the steps you can follow to handle UserRecoverableAuthIOException Exception properly and you can even avoid getting that exception when back pressed.
In some cases if you are receiving that error mean the activity is destroyed so you shouldn't depend on the activity
You need to
create fresh com.google.api.services.tasks.Tasks object from
Context of Service not from any Activity directly like shown in 'tasks-android-sample'
When you get Exception
You need show a notification with PendingIntent from Service
PendingIntent should contain the reference to an Activity , say
HomeActivity
Activity should handle the intent extra and should do
the required things like showing choose account dialog
you can go through the sample code here (GoogleTasksService)
What you can do, in this case don't use multiple activities.
By switching to views you can achieve your task.

Reconnect to a device after device crashed

I have the following problem with the libusb-java and some self-made devices.
It could happen that such a device disconnects from the USB Port because it drains to much power (as an example: i have a USB-LED Light which needs sometimes more than 500mA).
In this case the USB Controller will reset the device and the device will startup normaly again.
Now i cant really detect such a problem except for trying to reinit the device on every Exception. But thats not working...
On Every Exception i call my init Method again, which looks like this:
private void initDevice() {
USB.init();
this.dev = USB.getDevice(idVendor, idProduct);
}
The Problem with that is, this runs without any problem, but the i get this error message when i want to send new data:
LibusbJava.controlMsg: error sending control message: Protocol error
How do i can reinit the device? Do i have to reset the bus or something?
You will need to call open() on the device - it is new for the system.

Fail to connect to camera Service

I had seen many questions on stack but no one is telling if a Fail to connect to camera service will occur, how to get rid of this RuntimeException.
I have an camera application its working fine, I already take care to release the resources but if somehow user install the other application which not releasing the resources properly, my application facing RuntimeException: Fail to connect to camera Service and hence got crashed, want to avoid this situation.
If i click on original camera application it shows me a AlertDialog
Camera error: Cannot connect to camera.
That's what i exactly want to handle this. I am trying this code to handle it but cant succeed yet.
try {
camera = Camera.open();
camera.setDisplayOrientation(90);
} catch (RuntimeException e) {
// TODO: handle exception
Log.d("Inside RunTime exception", e+"//");
camera.setErrorCallback(errorCallback);
reConnectCameraVideo();
} catch(Exception e) {
finish();
}
but camera object returning null on camera.setErrorCallback because it wont open.
setErrorCallback() cannot be used for the case where the Camera will not open. You appear to be trying to still use the Camera -- AFAIK this is impossible until the user reboots their phone if some other app leaked the Camera. Simply display your own message to that effect.
Also:
Use an error logging service, like ACRA, Flurry, BugSense, etc.
Never blindly finish an activity due to an exception, as in your last catch block. Always do something to let the user and/or you (via the error logging service) know about the exception

Categories

Resources