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