[Android] VideoPlayerActivity: kill a lint warning

Edward Wang git at videolan.org
Thu Mar 27 15:29:15 CET 2014


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Mar 27 10:29:10 2014 -0400| [01c03f38d147febfef6c119c89fdc79e800571ac] | committer: Edward Wang

VideoPlayerActivity: kill a lint warning

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=01c03f38d147febfef6c119c89fdc79e800571ac
---

 .../videolan/vlc/gui/video/VideoPlayerActivity.java   |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index b2783ee..976b3b9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -395,7 +395,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
 
         if (mMediaRouter != null) {
             // Stop listening for changes to media routes.
-            mMediaRouter.removeCallback(mMediaRouterCallback);
+            mediaRouterAddCallback(false);
         }
 
         if(mSwitchingView) {
@@ -503,10 +503,23 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
 
         if (mMediaRouter != null) {
             // Listen for changes to media routes.
-            mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback);
+            mediaRouterAddCallback(true);
         }
+    }
 
+    /**
+     * Add or remove MediaRouter callbacks. This is provided for version targeting.
+     *
+     * @param add true to add, false to remove
+     */
+    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+    private void mediaRouterAddCallback(boolean add) {
+        if(!LibVlcUtil.isJellyBeanMR1OrLater() || mMediaRouter == null) return;
 
+        if(add)
+            mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback);
+        else
+            mMediaRouter.removeCallback(mMediaRouterCallback);
     }
 
     private void startPlayback() {



More information about the Android mailing list