Merge pull request #1404 from TomHennen/fix_huawei_npe

Fix huawei npe
This commit is contained in:
Tom Hennen 2015-11-22 19:16:35 -05:00
commit 2e18d95a74
3 changed files with 19 additions and 5 deletions

View File

@ -1,6 +1,10 @@
Change Log
==========
Version 1.4.0.12
----------------
* Fix for crash on Huawei devices (media buttons may not work)
Version 1.4
-----------
* BLUETOOTH PERMISSION: Needed to be able to resume playback when a Bluetooth device reconnects with your phone

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.danoeh.antennapod"
android:versionCode="1040011"
android:versionName="1.4.0.11">
android:versionCode="1040012"
android:versionName="1.4.0.12">
<!--
Version code schema:
"1.2.3-SNAPSHOT" -> 1020300

View File

@ -116,9 +116,19 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre
PendingIntent buttonReceiverIntent = PendingIntent.getBroadcast(context, 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mediaSession = new MediaSessionCompat(context, TAG, eventReceiver, buttonReceiverIntent);
mediaSession.setCallback(sessionCallback);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setActive(true);
try {
mediaSession.setCallback(sessionCallback);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setActive(true);
} catch (NullPointerException npe) {
// on some devices (Huawei) setting active can cause a NullPointerException
// even with correct use of the api.
// See http://stackoverflow.com/questions/31556679/android-huawei-mediassessioncompat
// and https://plus.google.com/+IanLake/posts/YgdTkKFxz7d
Log.e(TAG, "NullPointerException while setting up MediaSession");
npe.printStackTrace();
}
mediaPlayer = null;
statusBeforeSeeking = null;