@Override public void onComplete() { if (subscription == null) { // Technically this check is not needed, since we are expecting Publishers to conform to the spec (new IllegalStateException("Publisher violated the Reactive Streams rule 1.09 signalling onComplete prior to onSubscribe.")).printStackTrace(System.err); } else { // Here we are not allowed to call any methods on the `Subscription` or the `Publisher`, as per rule 2.3 // And anyway, the `Subscription` is considered to be cancelled if this method gets called, as per rule 2.4 } } }
@Override public void onError(final Throwable t) { if (subscription == null) { // Technically this check is not needed, since we are expecting Publishers to conform to the spec (new IllegalStateException("Publisher violated the Reactive Streams rule 1.09 signalling onError prior to onSubscribe.")).printStackTrace(System.err); } else { // As per rule 2.13, we need to throw a `java.lang.NullPointerException` if the `Throwable` is `null` if (t == null) throw null; // Here we are not allowed to call any methods on the `Subscription` or the `Publisher`, as per rule 2.3 // And anyway, the `Subscription` is considered to be cancelled if this method gets called, as per rule 2.4 } }
public void setPosition (float position) { if (player == null) return; try { if (!isPrepared) { player.prepare(); isPrepared = true; } player.seekTo((int)(position * 1000)); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public void setPosition (float position) { if (player == null) return; try { if (!isPrepared) { player.prepare(); isPrepared = true; } player.seekTo((int)(position * 1000)); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@Override public void play () { if (player == null) return; try { if (player.isPlaying()) return; } catch (Exception e) { // NOTE: isPlaying() can potentially throw an exception and crash the application e.printStackTrace(); return; } try { if (!isPrepared) { player.prepare(); isPrepared = true; } player.start(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@Override public void play () { if (player == null) return; try { if (player.isPlaying()) return; } catch (Exception e) { // NOTE: isPlaying() can potentially throw an exception and crash the application e.printStackTrace(); return; } try { if (!isPrepared) { player.prepare(); isPrepared = true; } player.start(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public long getDuration() { long duration = 0; //TODO MediaPlayer 判空的问题 // if (JZMediaManager.instance().mediaPlayer == null) return duration; try { duration = JZMediaManager.getDuration(); } catch (IllegalStateException e) { e.printStackTrace(); return duration; } return duration; }
@Override public void seekTo(long time) { try { mediaPlayer.seekTo((int) time); } catch (IllegalStateException e) { e.printStackTrace(); } }
private void done() { //On this line we could add a guard against `!done`, but since rule 3.7 says that `Subscription.cancel()` is idempotent, we don't need to. done = true; // If we `whenNext` throws an exception, let's consider ourselves done (not accepting more elements) try { subscription.cancel(); // Cancel the subscription } catch(final Throwable t) { //Subscription.cancel is not allowed to throw an exception, according to rule 3.15 (new IllegalStateException(subscription + " violated the Reactive Streams rule 3.15 by throwing an exception from cancel.", t)).printStackTrace(System.err); } }
private final void done() { //On this line we could add a guard against `!done`, but since rule 3.7 says that `Subscription.cancel()` is idempotent, we don't need to. done = true; // If `whenNext` throws an exception, let's consider ourselves done (not accepting more elements) if (subscription != null) { // If we are bailing out before we got a `Subscription` there's little need for cancelling it. try { subscription.cancel(); // Cancel the subscription } catch(final Throwable t) { //Subscription.cancel is not allowed to throw an exception, according to rule 3.15 (new IllegalStateException(subscription + " violated the Reactive Streams rule 3.15 by throwing an exception from cancel.", t)).printStackTrace(System.err); } } }
private void handleOnError(final Throwable error) { if (subscription == null) { // Technically this check is not needed, since we are expecting Publishers to conform to the spec // Publisher is not allowed to signal onError before onSubscribe according to rule 1.09 (new IllegalStateException("Publisher violated the Reactive Streams rule 1.09 signalling onError prior to onSubscribe.")).printStackTrace(System.err); } else { done = true; // Obey rule 2.4 whenError(error); } }
public void setVolume(final float vol) { try { mCurrentMediaPlayer.setVolume(vol, vol); } catch (IllegalStateException e) { e.printStackTrace(); } }
private void handleOnComplete() { if (subscription == null) { // Technically this check is not needed, since we are expecting Publishers to conform to the spec // Publisher is not allowed to signal onComplete before onSubscribe according to rule 1.09 (new IllegalStateException("Publisher violated the Reactive Streams rule 1.09 signalling onComplete prior to onSubscribe.")).printStackTrace(System.err); } else { done = true; // Obey rule 2.4 whenComplete(); } }
public long getCurrentPositionWhenPlaying() { long position = 0; //TODO 这块的判断应该根据MediaPlayer来 if (currentState == CURRENT_STATE_PLAYING || currentState == CURRENT_STATE_PAUSE) { try { position = JZMediaManager.getCurrentPosition(); } catch (IllegalStateException e) { e.printStackTrace(); return position; } } return position; }
@Override public void onDestroyView() { if (mUnbinder != null && mUnbinder != Unbinder.EMPTY) { try { mUnbinder.unbind(); } catch (IllegalStateException e) { e.printStackTrace(); //fix Bindings already cleared Timber.w("onDestroyView: " + e.getMessage()); } } }
@Override public void onComplete() { if (subscription == null) { // Technically this check is not needed, since we are expecting Publishers to conform to the spec (new IllegalStateException("Publisher violated the Reactive Streams rule 1.09 signalling onComplete prior to onSubscribe.")).printStackTrace(System.err); } else { // Here we are not allowed to call any methods on the `Subscription` or the `Publisher`, as per rule 2.3 // And anyway, the `Subscription` is considered to be cancelled if this method gets called, as per rule 2.4 } } }
@Override public void onError(final Throwable t) { if (subscription == null) { // Technically this check is not needed, since we are expecting Publishers to conform to the spec (new IllegalStateException("Publisher violated the Reactive Streams rule 1.09 signalling onError prior to onSubscribe.")).printStackTrace(System.err); } else { // As per rule 2.13, we need to throw a `java.lang.NullPointerException` if the `Throwable` is `null` if (t == null) throw null; // Here we are not allowed to call any methods on the `Subscription` or the `Publisher`, as per rule 2.3 // And anyway, the `Subscription` is considered to be cancelled if this method gets called, as per rule 2.4 } }
public void setDataSource(final String path) { try { mIsInitialized = setDataSourceImpl(mCurrentMediaPlayer, path); if (mIsInitialized) { setNextDataSource(null); } } catch (IllegalStateException e) { e.printStackTrace(); } }
private void done() { //On this line we could add a guard against `!done`, but since rule 3.7 says that `Subscription.cancel()` is idempotent, we don't need to. done = true; // If we `whenNext` throws an exception, let's consider ourselves done (not accepting more elements) try { subscription.cancel(); // Cancel the subscription } catch(final Throwable t) { //Subscription.cancel is not allowed to throw an exception, according to rule 3.15 (new IllegalStateException(subscription + " violated the Reactive Streams rule 3.15 by throwing an exception from cancel.", t)).printStackTrace(System.err); } }
@Override public Object invoke(MethodInvocation mi) throws Throwable { String task = "get invocation on way IN"; try { MethodInvocation current = ExposeInvocationInterceptor.currentInvocation(); assertEquals(mi.getMethod(), current.getMethod()); Object retval = mi.proceed(); task = "get invocation on way OUT"; assertEquals(current, ExposeInvocationInterceptor.currentInvocation()); return retval; } catch (IllegalStateException ex) { System.err.println(task + " for " + mi.getMethod()); ex.printStackTrace(); throw ex; } } }