public void handleCommandResources ( EventModel eventModel ) { List < ResourceModel < String >> resourceModels = eventModel . getListResourceContainer ( ) . provideResource ( CommandResource . ResourceID ) . stream ( ) . filter ( resourceModel -> resourceModel . getResource ( ) instanceof String ) . map ( resourceModel -> { try { //noinspection unchecked return ( ResourceModel < String > ) resourceModel ; } catch ( ClassCastException e ) { return null ; } } ) . filter ( Objects :: nonNull ) . collect ( Collectors . toList ( ) ) ; for ( ResourceModel < String > resourceModel : resourceModels ) { if ( ! CommandResource . verifyCommand ( resourceModel . getResource ( ) ) ) continue ; if ( ! CommandResource . verifyCapabilities ( resourceModel . getResource ( ) , capabilities ) ) { musicHelper . playerError ( PlayerError . ERROR_NOT_ABLE + "command: " + resourceModel . getResource ( ) , resourceModel . getProvider ( ) ) ; continue ; } switch ( resourceModel . getResource ( ) ) { case CommandResource . PLAY : if ( ! musicProvider . isPlaying ( ) ) playPause . accept ( resourceModel . getResource ( ) ) ; break ; case CommandResource . PAUSE : if ( musicProvider . isPlaying ( ) ) playPause . accept ( resourceModel . getResource ( ) ) ; break ; case CommandResource . SELECT_TRACK : handleSelectTrack ( eventModel , resourceModel ) ; break ; case CommandResource . NEXT : nextPrevious . accept ( resourceModel . getResource ( ) ) ; break ; case CommandResource . PREVIOUS : nextPrevious . accept ( resourceModel . getResource ( ) ) ; break ; case CommandResource . JUMP : handleJump ( eventModel , resourceModel ) ; break ; case CommandResource . CHANGE_PLAYBACK : changePlayback . accept ( resourceModel . getResource ( ) ) ; break ; case CommandResource . CHANGE_VOLUME : handleVolume ( eventModel , resourceModel ) ; break ; case CommandResource . STOP : stopCallback . run ( ) ; break ; } } }
this method gets called when a new Command was found . It automatically fires the update Event or an error