to make it easier for app to integrate with video players ▪ Manage between ads and content ▪ Components: › Remote API call (aka HTTP call) › Instrumentation › UI/UX according to company brand › Error handling
to make it easier for app to integrate with video players ▪ Manage between ads and content ▪ Components: › Remote API call (aka HTTP call) › Instrumentation › UI/UX according to company brand › Error handling
player listener → ugly! • Clock need to maintain state • Frozen detection (event) depends on player state • Update the seekbar UI to reflect playback position • Detect Inactivity
acc = 0; for ( int i = 0; i < list.length; i++ ) { acc = acc + 3 * list[i]; } Functional Programming Build Complexity out of Simplicity using Composition RxJava sumInteger( from(list) .map((num) -> { 3 * num }) ).subscribe(/* do with the total */); Haskell sum (map (3*) list)
play playing() .subscribe((i) -> { mSubscription = mClockObservable.connect(); }, RxLog.e(TAG, "ouch!!")); // stop when player is pause or complete or released Observable.merge(paused(), playComplete(), released()) .subscribe((integer) -> { mSubscription.unsubscribe(); }, RxLog.e(TAG, "ouch!!")); player clock subscribe playing paused / complete/ released
.publish(); Observable<Long> changed() { return mClockObservable .distinctUntilChanged(); } Observable<Integer> frozen(final int gracePeriod) { return mClockObservable .map(calculateFrozenTime()) .filter((frozenTime) -> frozenTime >= gracePeriod); } Map the clock value to playback position Only emit when position changed changed() .subscribe(()-> {/*update seekbar position*/}); frozen() .subscribe(()-> {/*reload player*/}); Emit when frozen for more than grace period
action void shouldStartPlayIn(long timeoutS, Action1<Throwable> actionWhenFailed) { Observable.merge(prepared(), released()) .first() .timeout(timeoutMs, SECONDS) .doOnError(RxLog.e(TAG, "Video not playing in " + timeoutS)) .observeOn(AndroidSchedulers.mainThread()) .subscribe((i) -> {/* no action if the condition satisfied*/}, actionWhenFailed); } prepared release first timeout Do something Do nothing