Your while isPlaying inside case 6 is blocking, until the track finishes. Hence the keypad is not getting checked. Nor any action on its output can be performed. You may want to check the keypad and return if it was pressed. Or convert the Case 6’s for loop to a state, as not to be blocking.