question

dasturrock avatar image
dasturrock asked

MediaController Crashing on Kindle Fire. Layout Inflate issue

Basically I have an activity that loads an audio file and plays it with a media controller present on the page. This works on other Android devices, including others running Ice Cream Sandwich, but the Kindle Fire HD 7 I'm using, currently on System Version 7.4.1, crashes everytime i try to load the activity as SetContentView causes a crash when the MediaController element is reached in the Android Xml file. It definitely seems to be a Kindle-specific issue. See Log Below I saw a solution to a similar problem for VideoViews here: http://forums.developer.amazon.com/forums/thread.jspa?threadID=429 This uses VideoView.setMediaController instead of having a MediaController element which avoids this issue but for audio playback I'd need another solution. Ideally I'd still like to use the MediaController to allow the same code to be used for multiple devices but a workaround may be necessary here. 06-04 13:41:36.643: E/AndroidRuntime(22774): FATAL EXCEPTION: main 06-04 13:41:36.643: E/AndroidRuntime(22774): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mothercare.android/com.mothercare.android.features.tunes.AudioPlayer}: java.lang.NullPointerException 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.app.ActivityThread.access$600(ActivityThread.java:126) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1172) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.os.Handler.dispatchMessage(Handler.java:99) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.os.Looper.loop(Looper.java:137) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.app.ActivityThread.main(ActivityThread.java:4586) 06-04 13:41:36.643: E/AndroidRuntime(22774): at java.lang.reflect.Method.invokeNative(Native Method) 06-04 13:41:36.643: E/AndroidRuntime(22774): at java.lang.reflect.Method.invoke(Method.java:511) 06-04 13:41:36.643: E/AndroidRuntime(22774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 06-04 13:41:36.643: E/AndroidRuntime(22774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 06-04 13:41:36.643: E/AndroidRuntime(22774): at dalvik.system.NativeStart.main(Native Method) 06-04 13:41:36.643: E/AndroidRuntime(22774): Caused by: java.lang.NullPointerException 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.widget.MediaController$VolumeController.init(MediaController.java:979) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.widget.MediaController$VolumeController.access$700(MediaController.java:924) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.widget.MediaController.initControllerView(MediaController.java:371) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.widget.MediaController.onFinishInflate(MediaController.java:151) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.view.LayoutInflater.rInflate(LayoutInflater.java:747) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 06-04 13:41:36.643: E/AndroidRuntime(22774): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:266) 06-04 13:41:36.643: E/AndroidRuntime(22774): at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:134) 06-04 13:41:36.643: E/AndroidRuntime(22774): at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262) 06-04 13:41:36.643: E/AndroidRuntime(22774): at com.mothercare.android.features.tunes.AudioPlayer.onCreate(AudioPlayer.java:83) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.app.Activity.performCreate(Activity.java:4635) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 06-04 13:41:36.643: E/AndroidRuntime(22774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031) 06-04 13:41:36.643: E/AndroidRuntime(22774): ... 11 more
fire tablet
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Dasturrock, According to MediaController documentation ( http://developer.android.com/reference/android/widget/MediaController.html), "The way to use this class is to instantiate it programatically." May I know why do you need it to be inflated from layout xml? What's the harm to instantiate a MediaController object in run time programatically?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dasturrock avatar image
dasturrock answered
Hi Sujoy, thank you for taking the time to respond to this. Well one advantage we find from inflating it through the layout is the media controls are present when the Activity starts, where as the working version I have now has a considerable delay until MyMediaController executes it's .show() method in onPrepared() which would be a little confusing to a user waiting for the audio to play. Either way, as mentioned it is possible to workaround this issue but there is still the problem of MediaController causing a crash when inflating only on the Kindle Fire.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Dasturrock, Thank you for your post. I have forwarded the issue to the concern team. I will post back after getting update from them.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.