[Crash] : avoid crash when leaving the application
This commit is contained in:
parent
ae30ab708e
commit
cdcfa8c28e
@ -113,8 +113,7 @@ public class VideoPlayerService extends Service {
|
|||||||
if (playbackState
|
if (playbackState
|
||||||
== ACTION_PLAY) { // this means that play is available, hence the audio is paused or stopped
|
== ACTION_PLAY) { // this means that play is available, hence the audio is paused or stopped
|
||||||
Log.v(TAG, "ACTION_PAUSE: " + playbackState);
|
Log.v(TAG, "ACTION_PAUSE: " + playbackState);
|
||||||
unregisterReceiver(myNoisyAudioStreamReceiver);
|
safeUnregisterReceiver();
|
||||||
myNoisyAudioStreamReceiver = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -137,14 +136,9 @@ public class VideoPlayerService extends Service {
|
|||||||
if (playerNotificationManager != null) {
|
if (playerNotificationManager != null) {
|
||||||
playerNotificationManager.setPlayer(null);
|
playerNotificationManager.setPlayer(null);
|
||||||
}
|
}
|
||||||
//Was seeing an error when exiting the program about about not unregistering the receiver.
|
//Was seeing an error when exiting the program about not unregistering the receiver.
|
||||||
try {
|
safeUnregisterReceiver();
|
||||||
if (null != myNoisyAudioStreamReceiver) {
|
|
||||||
this.unregisterReceiver(myNoisyAudioStreamReceiver);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("VideoPlayerService", "attempted to unregister a nonregistered service");
|
|
||||||
}
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.release();
|
player.release();
|
||||||
player = null;
|
player = null;
|
||||||
@ -152,6 +146,15 @@ public class VideoPlayerService extends Service {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void safeUnregisterReceiver()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
unregisterReceiver(myNoisyAudioStreamReceiver);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("VideoPlayerService", "attempted to unregister a nonregistered service");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user