OSDN Git Service

VideoView2: Add custom actions API
authorHyundo Moon <hdmoon@google.com>
Thu, 25 Jan 2018 08:34:05 +0000 (17:34 +0900)
committerHyundo Moon <hdmoon@google.com>
Fri, 26 Jan 2018 03:58:55 +0000 (12:58 +0900)
Test: Using VideoViewTest application
Change-Id: I941bf0f9605918b0e0f9e4684327eee9ffe24e11

core/java/android/widget/VideoView2.java
media/java/android/media/update/VideoView2Provider.java

index 7f0c086..e376b0f 100644 (file)
@@ -24,10 +24,12 @@ import android.media.AudioAttributes;
 import android.media.AudioManager;
 import android.media.MediaPlayerBase;
 import android.media.session.MediaController;
+import android.media.session.PlaybackState;
 import android.media.update.ApiLoader;
 import android.media.update.VideoView2Provider;
 import android.media.update.ViewProvider;
 import android.net.Uri;
+import android.os.Bundle;
 import android.util.AttributeSet;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
@@ -316,6 +318,19 @@ public class VideoView2 extends FrameLayout {
     }
 
     /**
+     * Sets custom actions which will be shown as custom buttons in {@link MediaControlView2}.
+     *
+     * @param actionList A list of {@link PlaybackState.CustomAction}. The return value of
+     *                   {@link PlaybackState.CustomAction#getIcon()} will be used to draw buttons
+     *                   in {@link MediaControlView2}.
+     * @param listener A listener to be called when a custom button is clicked.
+     */
+    public void setCustomActions(List<PlaybackState.CustomAction> actionList,
+            OnCustomActionListener listener) {
+        mProvider.setCustomActions_impl(actionList, listener);
+    }
+
+    /**
      * Registers a callback to be invoked when the media file is loaded and ready to go.
      *
      * @param l the callback that will be run.
@@ -449,6 +464,22 @@ public class VideoView2 extends FrameLayout {
         void onFullScreenChanged(boolean fullScreen);
     }
 
+    /**
+     * Interface definition of a callback to be invoked to inform that a custom action is performed.
+     *
+     * TODO: When MediaSession2 is ready, modify the method to match the signature.
+     */
+    public interface OnCustomActionListener {
+        /**
+         * Called to indicate that a custom action is performed.
+         *
+         * @param action The action that was originally sent in the
+         *               {@link PlaybackState.CustomAction}.
+         * @param extras Optional extras.
+         */
+        void onCustomAction(String action, Bundle extras);
+    }
+
     @Override
     protected void onAttachedToWindow() {
         mProvider.onAttachedToWindow_impl();
index 5c05ce4..df792ad 100644 (file)
@@ -19,6 +19,7 @@ package android.media.update;
 import android.media.AudioAttributes;
 import android.media.MediaPlayerBase;
 import android.media.session.MediaController;
+import android.media.session.PlaybackState;
 import android.net.Uri;
 import android.widget.MediaControlView2;
 import android.widget.VideoView2;
@@ -58,6 +59,8 @@ public interface VideoView2Provider extends ViewProvider {
     void setVideoURI_impl(Uri uri, Map<String, String> headers);
     void setViewType_impl(int viewType);
     int getViewType_impl();
+    void setCustomActions_impl(List<PlaybackState.CustomAction> actionList,
+            VideoView2.OnCustomActionListener listener);
     void setOnPreparedListener_impl(VideoView2.OnPreparedListener l);
     void setOnCompletionListener_impl(VideoView2.OnCompletionListener l);
     void setOnErrorListener_impl(VideoView2.OnErrorListener l);