Buggy code:
public class MusicService extends Service implements OnAudioFocusChangeListener , MediaPlayer . OnCompletionListener , MediaPlayer . OnErrorListener , MediaPlayer . OnPreparedListener , MediaButtonReceiverListener { public class MusicBinder extends Binder { MusicService getService ( ) { } } private class HeadsetStateReceiver extends BroadcastReceiver { @ Override public void onReceive ( Context context , Intent intent ) { if ( ( intent . getAction ( ) . equals ( ACTION_HEADSET_PLUG ) ) && ( ! ( isInitialStickyBroadcast ( ) ) ) ) { int state = intent . getIntExtra ( "state" , ( - 1 ) ) ; switch ( state ) { case 0 : <START_BUG> player . pause ( ) ; <END_BUG> break ; case 1 : break ; } } } } private static final int NOTIFY_ID = 1 ; private Song currentSong ; private MusicService . HeadsetStateReceiver headsetStateReceiver ; private final IBinder musicBind = new MusicService . MusicBinder ( ) ; private final BroadcastReceiver onBluetoothStateChangeReceiver = new BroadcastReceiver ( ) { @ Override public void onReceive ( Context context , Intent intent ) { String action = intent . getAction ( ) ; if ( ( intent . getIntExtra ( EXTRA_STATE , ( - 1 ) ) ) == ( BluetoothAdapter . STATE_OFF ) ) { pause ( ) ; } if ( action . equals ( "android.bluetooth.device.action.ACL_CONNECTED" ) ) { Log . d ( "Z" , "Received:<seq2seq4repair_space>Bluetooth<seq2seq4repair_space>Connected" ) ; } if ( ( action . equals ( "android.bluetooth.device.action.ACL_DISCONNECTED" ) ) || ( action . equals ( "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" ) ) ) { pause ( ) ; Log . d ( "Z" , "Received:<seq2seq4repair_space>Bluetooth<seq2seq4repair_space>Disconnected" ) ; } } } ; private int pauseDuration = 0 ; private int pausePosition = 0 ; private MediaPlayer player ; private ArrayList < Song > playQueue = new ArrayList < Song > ( ) ; private Random rand ; private boolean shuffle = false ; private ArrayList < Song > songLibrary ; public void addToQueue ( Song song ) { } public boolean audioFocusGranted ( ) { } public Song getCurrentSong ( ) { } public int getDuration ( ) { } public int getPauseDuration ( ) { } public int getPausePosition ( ) { } public int getPosition ( ) { } public Song getSongById ( long songId ) { } public Song getSongByIndex ( int index ) { } public void initMusicPlayer ( ) { } public boolean isPlaying ( ) { } public boolean isShuffling ( ) { } @ Override public void onAudioFocusChange ( int focusChange ) { } @ Override public IBinder onBind ( Intent intent ) { } @ Override public void onCompletion ( MediaPlayer mp ) { } @ Override public void onCreate ( ) { } @ Override public void onDestroy ( ) { } @ Override public boolean onError ( MediaPlayer mp , int what , int extra ) { } @ Override public void onMediaButtonReceived ( int keyCode ) { } @ Override public void onPrepared ( MediaPlayer mp ) { } @ Override public int onStartCommand ( Intent intent , int flags , int startId ) { } @ Override public boolean onUnbind ( Intent intent ) { } public void pause ( ) { } public void play ( ) { } public void playNext ( ) { } public void playPrevious ( ) { } public void playSong ( Song song ) { } public void removeFromPlaylist ( Song song ) { } public void seek ( int posn ) { } public void setPausePosition ( int pausePosition ) { } public void setShuffle ( boolean shuffle ) { } public void setSong ( Song song ) { } public void setSongLibrary ( ArrayList < Song > songs ) { } public void toggleShuffle ( ) { } private void registerMediaButtonListener ( ) { } }

Fix:
pause ( ) ;