Skip to content

Commit

Permalink
fix: use getSystemService workaround for versions < Android 6 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah authored Jan 12, 2020
1 parent f28f7af commit 9407afd
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@

import java.util.concurrent.CountDownLatch;


public class CaptioningChangeListener extends CaptioningManager.CaptioningChangeListener {
private Context mContext;

private CaptioningManager mCaptioningManager;

private CaptioningManager getCaptioningManager() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return (CaptioningManager) mContext.getSystemService(Context.CAPTIONING_SERVICE);
} else {
// Android <= 5 bug workaround
Expand All @@ -28,19 +27,19 @@ private CaptioningManager getCaptioningManager() {

Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
mCaptioningManager = (CaptioningManager) mContext.getSystemService(Context.CAPTIONING_SERVICE);
latch.countDown();
}
@Override
public void run() {
mCaptioningManager = (CaptioningManager) mContext.getSystemService(Context.CAPTIONING_SERVICE);
latch.countDown();
}
});

try {
latch.await();
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
e.printStackTrace();
}

return mCaptioningManager;
}
}
Expand Down

0 comments on commit 9407afd

Please sign in to comment.