private RendererState getPrimaryState() { libvlc_state_t state = renderer.getVLCJPlayer().getMediaState(); if (state == null) { return RendererState.ERROR; } switch (state) { case libvlc_Buffering: return RendererState.BUFFERING; case libvlc_Ended: return RendererState.STOPPED; case libvlc_Error: return RendererState.ERROR; case libvlc_NothingSpecial: return RendererState.STOPPED; case libvlc_Opening: return RendererState.BUFFERING; case libvlc_Paused: return RendererState.PAUSED; case libvlc_Playing: return RendererState.PLAYING; case libvlc_Stopped: return RendererState.STOPPED; } return RendererState.STOPPED; }
@Override public void playing(MediaPlayer mediaPlayer) { renderer.setState(RendererState.PLAYING); long position = getSeekPosition(); if (position > 0) { mediaPlayer.setTime(position); } }
@Override public void finished(MediaPlayer mediaPlayer) { // Used for YouTube videos List<String> subItems = mediaPlayer.subItems(); if (subItems != null && !subItems.isEmpty()) { String subItemURI = subItems.get(0); mediaPlayer.playMedia(subItemURI); } else { renderer.setState(RendererState.STOPPED); } }
@Override public void error(MediaPlayer mediaPlayer) { renderer.setState(RendererState.ERROR); PlayBlock.log(Level.INFO, "Media has encountered an error!"); }
@Override public void stopped(MediaPlayer mediaPlayer) { renderer.setState(RendererState.STOPPED); }
@Override public void paused(MediaPlayer mediaPlayer) { renderer.setState(RendererState.PAUSED); }
@Override public void opening(MediaPlayer mediaPlayer) { renderer.setState(getPrimaryState()); }
@Override public void buffering(MediaPlayer mediaPlayer, float newCache) { // This would override a PLAYING state renderer.setState(getPrimaryState()); }