Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.widget; |
| 18 | |
| 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
| 22 | import android.content.Context; |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 23 | import android.media.AudioAttributes; |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 24 | import android.media.AudioManager; |
Sungsoo Lim | af2a1ad | 2018-01-24 11:36:10 +0900 | [diff] [blame] | 25 | import android.media.MediaPlayerBase; |
Sungsoo Lim | 82af545 | 2018-01-25 15:02:12 +0900 | [diff] [blame] | 26 | import android.media.session.MediaController; |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 27 | import android.media.update.ApiLoader; |
| 28 | import android.media.update.VideoView2Provider; |
| 29 | import android.media.update.ViewProvider; |
| 30 | import android.net.Uri; |
| 31 | import android.util.AttributeSet; |
| 32 | import android.view.KeyEvent; |
| 33 | import android.view.MotionEvent; |
| 34 | |
| 35 | import java.lang.annotation.Retention; |
| 36 | import java.lang.annotation.RetentionPolicy; |
Sungsoo Lim | af2a1ad | 2018-01-24 11:36:10 +0900 | [diff] [blame] | 37 | import java.util.List; |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 38 | import java.util.Map; |
| 39 | |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 40 | // TODO: Use @link tag to refer MediaPlayer2 in docs once MediaPlayer2.java is submitted. Same to |
| 41 | // MediaSession2. |
| 42 | // TODO: change the reference from MediaPlayer to MediaPlayer2. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 43 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 44 | * Displays a video file. VideoView2 class is a View class which is wrapping MediaPlayer2 so that |
| 45 | * developers can easily implement a video rendering application. |
| 46 | * |
| 47 | * <p> |
| 48 | * <em> Data sources that VideoView2 supports : </em> |
| 49 | * VideoView2 can play video files and audio-only fiels as |
| 50 | * well. It can load from various sources such as resources or content providers. The supported |
| 51 | * media file formats are the same as MediaPlayer2. |
| 52 | * |
| 53 | * <p> |
| 54 | * <em> View type can be selected : </em> |
| 55 | * VideoView2 can render videos on top of TextureView as well as |
| 56 | * SurfaceView selectively. The default is SurfaceView and it can be changed using |
| 57 | * {@link #setViewType(int)} method. Using SurfaceView is recommended in most cases for saving |
| 58 | * battery. TextureView might be preferred for supporting various UIs such as animation and |
| 59 | * translucency. |
| 60 | * |
| 61 | * <p> |
| 62 | * <em> Differences between {@link VideoView} class : </em> |
| 63 | * VideoView2 covers and inherits the most of |
| 64 | * VideoView's functionalities. The main differences are |
| 65 | * <ul> |
| 66 | * <li> VideoView2 inherits FrameLayout and renders videos using SurfaceView and TextureView |
| 67 | * selectively while VideoView inherits SurfaceView class. |
| 68 | * <li> VideoView2 is integrated with MediaControlView2 and a default MediaControlView2 instance is |
| 69 | * attached to VideoView2 by default. If a developer does not want to use the default |
| 70 | * MediaControlView2, needs to set enableControlView attribute to false. For instance, |
| 71 | * <pre> |
| 72 | * <VideoView2 |
| 73 | * android:id="@+id/video_view" |
| 74 | * xmlns:widget="http://schemas.android.com/apk/com.android.media.update" |
| 75 | * widget:enableControlView="false" /> |
| 76 | * </pre> |
| 77 | * If a developer wants to attach a customed MediaControlView2, then set enableControlView attribute |
| 78 | * to false and assign the customed media control widget using {@link #setMediaControlView2}. |
| 79 | * <li> VideoView2 is integrated with MediaPlayer2 while VideoView is integrated with MediaPlayer. |
Sungsoo Lim | 82af545 | 2018-01-25 15:02:12 +0900 | [diff] [blame] | 80 | * <li> VideoView2 is integrated with MediaSession and so it responses with media key events. |
| 81 | * A VideoView2 keeps a MediaSession instance internally and connects it to a corresponding |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 82 | * MediaControlView2 instance. |
| 83 | * </p> |
| 84 | * </ul> |
| 85 | * |
| 86 | * <p> |
| 87 | * <em> Audio focus and audio attributes : </em> |
| 88 | * By default, VideoView2 requests audio focus with |
| 89 | * {@link AudioManager#AUDIOFOCUS_GAIN}. Use {@link #setAudioFocusRequest(int)} to change this |
| 90 | * behavior. The default {@link AudioAttributes} used during playback have a usage of |
| 91 | * {@link AudioAttributes#USAGE_MEDIA} and a content type of |
| 92 | * {@link AudioAttributes#CONTENT_TYPE_MOVIE}, use {@link #setAudioAttributes(AudioAttributes)} to |
| 93 | * modify them. |
| 94 | * |
| 95 | * <p> |
| 96 | * Note: VideoView2 does not retain its full state when going into the background. In particular, it |
| 97 | * does not restore the current play state, play position, selected tracks. Applications should save |
| 98 | * and restore these on their own in {@link android.app.Activity#onSaveInstanceState} and |
| 99 | * {@link android.app.Activity#onRestoreInstanceState}. |
| 100 | * |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 101 | * @hide |
| 102 | */ |
| 103 | public class VideoView2 extends FrameLayout { |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 104 | /** @hide */ |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 105 | @IntDef({ |
| 106 | VIEW_TYPE_TEXTUREVIEW, |
| 107 | VIEW_TYPE_SURFACEVIEW |
| 108 | }) |
| 109 | @Retention(RetentionPolicy.SOURCE) |
| 110 | public @interface ViewType {} |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 111 | |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 112 | public static final int VIEW_TYPE_SURFACEVIEW = 1; |
| 113 | public static final int VIEW_TYPE_TEXTUREVIEW = 2; |
| 114 | |
| 115 | private final VideoView2Provider mProvider; |
| 116 | |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 117 | public VideoView2(@NonNull Context context) { |
| 118 | this(context, null); |
| 119 | } |
| 120 | |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 121 | public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs) { |
| 122 | this(context, attrs, 0); |
| 123 | } |
| 124 | |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 125 | public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { |
| 126 | this(context, attrs, defStyleAttr, 0); |
| 127 | } |
| 128 | |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 129 | public VideoView2( |
| 130 | @NonNull Context context, @Nullable AttributeSet attrs, |
| 131 | int defStyleAttr, int defStyleRes) { |
| 132 | super(context, attrs, defStyleAttr, defStyleRes); |
| 133 | |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 134 | mProvider = ApiLoader.getProvider(context).createVideoView2(this, new SuperProvider(), |
| 135 | attrs, defStyleAttr, defStyleRes); |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @hide |
| 140 | */ |
| 141 | public VideoView2Provider getProvider() { |
| 142 | return mProvider; |
| 143 | } |
| 144 | |
| 145 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 146 | * Sets MediaControlView2 instance. It will replace the previously assigned MediaControlView2 |
| 147 | * instance if any. |
| 148 | * |
| 149 | * @param mediaControlView a media control view2 instance. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 150 | */ |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 151 | public void setMediaControlView2(MediaControlView2 mediaControlView) { |
| 152 | mProvider.setMediaControlView2_impl(mediaControlView); |
| 153 | } |
| 154 | |
| 155 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 156 | * Returns MediaControlView2 instance which is currently attached to VideoView2 by default or by |
| 157 | * {@link #setMediaControlView2} method. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 158 | */ |
| 159 | public MediaControlView2 getMediaControlView2() { |
| 160 | return mProvider.getMediaControlView2_impl(); |
| 161 | } |
| 162 | |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 163 | |
| 164 | /** |
Sungsoo Lim | 82af545 | 2018-01-25 15:02:12 +0900 | [diff] [blame] | 165 | * Returns MediaController instance which is connected with MediaSession that VideoView2 is |
| 166 | * using. This method should be called when VideoView2 is attached to window, or it throws |
| 167 | * IllegalStateException, since internal MediaSession instance is not available until |
| 168 | * this view is attached to window. Please check {@link android.view.View#isAttachedToWindow} |
| 169 | * before calling this method. |
| 170 | * |
| 171 | * @throws IllegalStateException if interal MediaSession is not created yet. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 172 | */ |
Sungsoo Lim | 82af545 | 2018-01-25 15:02:12 +0900 | [diff] [blame] | 173 | public MediaController getMediaController() { |
| 174 | return mProvider.getMediaController_impl(); |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 178 | * Returns the audio session ID. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 179 | */ |
| 180 | public int getAudioSessionId() { |
| 181 | return mProvider.getAudioSessionId_impl(); |
| 182 | } |
| 183 | |
| 184 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 185 | * Starts rendering closed caption or subtitles if there is any. The first subtitle track will |
| 186 | * be chosen by default if there multiple subtitle tracks exist. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 187 | */ |
| 188 | public void showSubtitle() { |
| 189 | mProvider.showSubtitle_impl(); |
| 190 | } |
| 191 | |
| 192 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 193 | * Stops showing closed captions or subtitles. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 194 | */ |
| 195 | public void hideSubtitle() { |
| 196 | mProvider.hideSubtitle_impl(); |
| 197 | } |
| 198 | |
Hyundo Moon | efeb45e | 2018-01-24 11:16:19 +0900 | [diff] [blame] | 199 | /** |
| 200 | * Sets full screen mode. |
| 201 | */ |
| 202 | public void setFullScreen(boolean fullScreen) { |
| 203 | mProvider.setFullScreen_impl(fullScreen); |
| 204 | } |
| 205 | |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 206 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 207 | * Sets playback speed. |
| 208 | * |
| 209 | * It is expressed as a multiplicative factor, where normal speed is 1.0f. If it is less than |
| 210 | * or equal to zero, it will be just ignored and nothing will be changed. If it exceeds the |
| 211 | * maximum speed that internal engine supports, system will determine best handling or it will |
| 212 | * be reset to the normal speed 1.0f. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 213 | * @param speed the playback speed. It should be positive. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 214 | */ |
Sungsoo Lim | 82af545 | 2018-01-25 15:02:12 +0900 | [diff] [blame] | 215 | // TODO: Support this via MediaController2. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 216 | public void setSpeed(float speed) { |
| 217 | mProvider.setSpeed_impl(speed); |
| 218 | } |
| 219 | |
| 220 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 221 | * Sets which type of audio focus will be requested during the playback, or configures playback |
| 222 | * to not request audio focus. Valid values for focus requests are |
| 223 | * {@link AudioManager#AUDIOFOCUS_GAIN}, {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT}, |
| 224 | * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK}, and |
| 225 | * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}. Or use |
| 226 | * {@link AudioManager#AUDIOFOCUS_NONE} to express that audio focus should not be |
| 227 | * requested when playback starts. You can for instance use this when playing a silent animation |
| 228 | * through this class, and you don't want to affect other audio applications playing in the |
| 229 | * background. |
| 230 | * |
| 231 | * @param focusGain the type of audio focus gain that will be requested, or |
Sungsoo Lim | af2a1ad | 2018-01-24 11:36:10 +0900 | [diff] [blame] | 232 | * {@link AudioManager#AUDIOFOCUS_NONE} to disable the use audio focus during |
| 233 | * playback. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 234 | */ |
| 235 | public void setAudioFocusRequest(int focusGain) { |
| 236 | mProvider.setAudioFocusRequest_impl(focusGain); |
| 237 | } |
| 238 | |
| 239 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 240 | * Sets the {@link AudioAttributes} to be used during the playback of the video. |
| 241 | * |
| 242 | * @param attributes non-null <code>AudioAttributes</code>. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 243 | */ |
| 244 | public void setAudioAttributes(@NonNull AudioAttributes attributes) { |
| 245 | mProvider.setAudioAttributes_impl(attributes); |
| 246 | } |
| 247 | |
| 248 | /** |
Sungsoo Lim | af2a1ad | 2018-01-24 11:36:10 +0900 | [diff] [blame] | 249 | * Sets a remote player for handling playback of the selected route from MediaControlView2. |
| 250 | * If this is not called, MediaCotrolView2 will not show the route button. |
| 251 | * |
| 252 | * @param routeCategories the list of media control categories in |
| 253 | * {@link android.support.v7.media.MediaControlIntent} |
| 254 | * @param player the player to handle the selected route. If null, a default |
| 255 | * route player will be used. |
| 256 | * @throws IllegalStateException if MediaControlView2 is not set. |
| 257 | */ |
| 258 | public void setRouteAttributes(@NonNull List<String> routeCategories, |
| 259 | @Nullable MediaPlayerBase player) { |
| 260 | mProvider.setRouteAttributes_impl(routeCategories, player); |
| 261 | } |
| 262 | |
| 263 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 264 | * Sets video path. |
| 265 | * |
| 266 | * @param path the path of the video. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 267 | */ |
| 268 | public void setVideoPath(String path) { |
| 269 | mProvider.setVideoPath_impl(path); |
| 270 | } |
| 271 | |
| 272 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 273 | * Sets video URI. |
| 274 | * |
| 275 | * @param uri the URI of the video. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 276 | */ |
| 277 | public void setVideoURI(Uri uri) { |
| 278 | mProvider.setVideoURI_impl(uri); |
| 279 | } |
| 280 | |
| 281 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 282 | * Sets video URI using specific headers. |
| 283 | * |
| 284 | * @param uri the URI of the video. |
| 285 | * @param headers the headers for the URI request. |
| 286 | * Note that the cross domain redirection is allowed by default, but that can be |
| 287 | * changed with key/value pairs through the headers parameter with |
| 288 | * "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value |
| 289 | * to disallow or allow cross domain redirection. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 290 | */ |
| 291 | public void setVideoURI(Uri uri, Map<String, String> headers) { |
| 292 | mProvider.setVideoURI_impl(uri, headers); |
| 293 | } |
| 294 | |
| 295 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 296 | * Selects which view will be used to render video between SurfacView and TextureView. |
| 297 | * |
| 298 | * @param viewType the view type to render video |
| 299 | * <ul> |
| 300 | * <li>{@link #VIEW_TYPE_SURFACEVIEW} |
| 301 | * <li>{@link #VIEW_TYPE_TEXTUREVIEW} |
| 302 | * </ul> |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 303 | */ |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 304 | public void setViewType(@ViewType int viewType) { |
| 305 | mProvider.setViewType_impl(viewType); |
| 306 | } |
| 307 | |
| 308 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 309 | * Returns view type. |
| 310 | * |
| 311 | * @return view type. See {@see setViewType}. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 312 | */ |
| 313 | @ViewType |
| 314 | public int getViewType() { |
| 315 | return mProvider.getViewType_impl(); |
| 316 | } |
| 317 | |
| 318 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 319 | * Registers a callback to be invoked when the media file is loaded and ready to go. |
| 320 | * |
| 321 | * @param l the callback that will be run. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 322 | */ |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 323 | public void setOnPreparedListener(OnPreparedListener l) { |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 324 | mProvider.setOnPreparedListener_impl(l); |
| 325 | } |
| 326 | |
| 327 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 328 | * Registers a callback to be invoked when the end of a media file has been reached during |
| 329 | * playback. |
| 330 | * |
| 331 | * @param l the callback that will be run. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 332 | */ |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 333 | public void setOnCompletionListener(OnCompletionListener l) { |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 334 | mProvider.setOnCompletionListener_impl(l); |
| 335 | } |
| 336 | |
| 337 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 338 | * Registers a callback to be invoked when an error occurs during playback or setup. If no |
| 339 | * listener is specified, or if the listener returned false, VideoView2 will inform the user of |
| 340 | * any errors. |
| 341 | * |
| 342 | * @param l The callback that will be run |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 343 | */ |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 344 | public void setOnErrorListener(OnErrorListener l) { |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 345 | mProvider.setOnErrorListener_impl(l); |
| 346 | } |
| 347 | |
| 348 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 349 | * Registers a callback to be invoked when an informational event occurs during playback or |
| 350 | * setup. |
| 351 | * |
| 352 | * @param l The callback that will be run |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 353 | */ |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 354 | public void setOnInfoListener(OnInfoListener l) { |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 355 | mProvider.setOnInfoListener_impl(l); |
| 356 | } |
| 357 | |
| 358 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 359 | * Registers a callback to be invoked when a view type change is done. |
| 360 | * {@see #setViewType(int)} |
| 361 | * @param l The callback that will be run |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 362 | */ |
| 363 | public void setOnViewTypeChangedListener(OnViewTypeChangedListener l) { |
| 364 | mProvider.setOnViewTypeChangedListener_impl(l); |
| 365 | } |
| 366 | |
| 367 | /** |
Hyundo Moon | efeb45e | 2018-01-24 11:16:19 +0900 | [diff] [blame] | 368 | * Registers a callback to be invoked when the fullscreen mode should be changed. |
| 369 | */ |
| 370 | public void setFullScreenChangedListener(OnFullScreenChangedListener l) { |
| 371 | mProvider.setFullScreenChangedListener_impl(l); |
| 372 | } |
| 373 | |
| 374 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 375 | * Interface definition of a callback to be invoked when the viw type has been changed. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 376 | */ |
| 377 | public interface OnViewTypeChangedListener { |
| 378 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 379 | * Called when the view type has been changed. |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 380 | * @see #setViewType(int) |
| 381 | * @param viewType |
| 382 | * <ul> |
| 383 | * <li>{@link #VIEW_TYPE_SURFACEVIEW} |
| 384 | * <li>{@link #VIEW_TYPE_TEXTUREVIEW} |
| 385 | * </ul> |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 386 | */ |
| 387 | void onViewTypeChanged(@ViewType int viewType); |
| 388 | } |
| 389 | |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 390 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 391 | * Interface definition of a callback to be invoked when the media source is ready for playback. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 392 | */ |
| 393 | public interface OnPreparedListener { |
| 394 | /** |
| 395 | * Called when the media file is ready for playback. |
| 396 | */ |
| 397 | void onPrepared(); |
| 398 | } |
| 399 | |
| 400 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 401 | * Interface definition for a callback to be invoked when playback of a media source has |
| 402 | * completed. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 403 | */ |
| 404 | public interface OnCompletionListener { |
| 405 | /** |
| 406 | * Called when the end of a media source is reached during playback. |
| 407 | */ |
| 408 | void onCompletion(); |
| 409 | } |
| 410 | |
| 411 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 412 | * Interface definition of a callback to be invoked when there has been an error during an |
| 413 | * asynchronous operation. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 414 | */ |
| 415 | public interface OnErrorListener { |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 416 | // TODO: Redefine error codes. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 417 | /** |
| 418 | * Called to indicate an error. |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 419 | * @param what the type of error that has occurred |
| 420 | * @param extra an extra code, specific to the error. |
| 421 | * @return true if the method handled the error, false if it didn't. |
| 422 | * @see MediaPlayer#OnErrorListener |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 423 | */ |
| 424 | boolean onError(int what, int extra); |
| 425 | } |
| 426 | |
| 427 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 428 | * Interface definition of a callback to be invoked to communicate some info and/or warning |
| 429 | * about the media or its playback. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 430 | */ |
| 431 | public interface OnInfoListener { |
| 432 | /** |
| 433 | * Called to indicate an info or a warning. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 434 | * @param what the type of info or warning. |
| 435 | * @param extra an extra code, specific to the info. |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 436 | * |
| 437 | * @see MediaPlayer#OnInfoListener |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 438 | */ |
| 439 | void onInfo(int what, int extra); |
| 440 | } |
| 441 | |
Hyundo Moon | efeb45e | 2018-01-24 11:16:19 +0900 | [diff] [blame] | 442 | /** |
| 443 | * Interface definition of a callback to be invoked to inform the fullscreen mode is changed. |
| 444 | */ |
| 445 | public interface OnFullScreenChangedListener { |
| 446 | /** |
| 447 | * Called to indicate a fullscreen mode change. |
| 448 | */ |
| 449 | void onFullScreenChanged(boolean fullScreen); |
| 450 | } |
| 451 | |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 452 | @Override |
Insun Kang | fd3fdfd | 2018-01-23 15:01:37 +0900 | [diff] [blame] | 453 | protected void onAttachedToWindow() { |
| 454 | mProvider.onAttachedToWindow_impl(); |
| 455 | } |
| 456 | |
| 457 | @Override |
| 458 | protected void onDetachedFromWindow() { |
| 459 | mProvider.onDetachedFromWindow_impl(); |
| 460 | } |
| 461 | |
| 462 | @Override |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 463 | public CharSequence getAccessibilityClassName() { |
| 464 | return mProvider.getAccessibilityClassName_impl(); |
| 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public boolean onTouchEvent(MotionEvent ev) { |
| 469 | return mProvider.onTouchEvent_impl(ev); |
| 470 | } |
| 471 | |
| 472 | @Override |
| 473 | public boolean onTrackballEvent(MotionEvent ev) { |
| 474 | return mProvider.onTrackballEvent_impl(ev); |
| 475 | } |
| 476 | |
| 477 | @Override |
| 478 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 479 | return mProvider.onKeyDown_impl(keyCode, event); |
| 480 | } |
| 481 | |
| 482 | @Override |
| 483 | public void onFinishInflate() { |
| 484 | mProvider.onFinishInflate_impl(); |
| 485 | } |
| 486 | |
| 487 | @Override |
| 488 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 489 | return mProvider.dispatchKeyEvent_impl(event); |
| 490 | } |
| 491 | |
| 492 | @Override |
| 493 | public void setEnabled(boolean enabled) { |
| 494 | mProvider.setEnabled_impl(enabled); |
| 495 | } |
| 496 | |
| 497 | private class SuperProvider implements ViewProvider { |
| 498 | @Override |
Insun Kang | fd3fdfd | 2018-01-23 15:01:37 +0900 | [diff] [blame] | 499 | public void onAttachedToWindow_impl() { |
| 500 | VideoView2.super.onAttachedToWindow(); |
| 501 | } |
| 502 | |
| 503 | @Override |
| 504 | public void onDetachedFromWindow_impl() { |
| 505 | VideoView2.super.onDetachedFromWindow(); |
| 506 | } |
| 507 | |
| 508 | @Override |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 509 | public CharSequence getAccessibilityClassName_impl() { |
| 510 | return VideoView2.super.getAccessibilityClassName(); |
| 511 | } |
| 512 | |
| 513 | @Override |
| 514 | public boolean onTouchEvent_impl(MotionEvent ev) { |
| 515 | return VideoView2.super.onTouchEvent(ev); |
| 516 | } |
| 517 | |
| 518 | @Override |
| 519 | public boolean onTrackballEvent_impl(MotionEvent ev) { |
| 520 | return VideoView2.super.onTrackballEvent(ev); |
| 521 | } |
| 522 | |
| 523 | @Override |
| 524 | public boolean onKeyDown_impl(int keyCode, KeyEvent event) { |
| 525 | return VideoView2.super.onKeyDown(keyCode, event); |
| 526 | } |
| 527 | |
| 528 | @Override |
| 529 | public void onFinishInflate_impl() { |
| 530 | VideoView2.super.onFinishInflate(); |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public boolean dispatchKeyEvent_impl(KeyEvent event) { |
| 535 | return VideoView2.super.dispatchKeyEvent(event); |
| 536 | } |
| 537 | |
| 538 | @Override |
| 539 | public void setEnabled_impl(boolean enabled) { |
| 540 | VideoView2.super.setEnabled(enabled); |
| 541 | } |
| 542 | } |
| 543 | } |