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 | |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 240 | // TODO: This should be revised after integration with MediaPlayer2. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 241 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 242 | * Sets playback speed. |
| 243 | * |
| 244 | * It is expressed as a multiplicative factor, where normal speed is 1.0f. If it is less than |
| 245 | * or equal to zero, it will be just ignored and nothing will be changed. If it exceeds the |
| 246 | * maximum speed that internal engine supports, system will determine best handling or it will |
| 247 | * be reset to the normal speed 1.0f. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 248 | * @param speed the playback speed. It should be positive. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 249 | */ |
| 250 | public void setSpeed(float speed) { |
| 251 | mProvider.setSpeed_impl(speed); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Returns current speed setting. |
| 256 | * |
| 257 | * If setSpeed() has never been called, returns the default value 1.0f. |
| 258 | * @return current speed setting |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 259 | */ |
| 260 | public float getSpeed() { |
| 261 | return mProvider.getSpeed_impl(); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Sets which type of audio focus will be requested during the playback, or configures playback |
| 266 | * to not request audio focus. Valid values for focus requests are |
| 267 | * {@link AudioManager#AUDIOFOCUS_GAIN}, {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT}, |
| 268 | * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK}, and |
| 269 | * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}. Or use |
| 270 | * {@link AudioManager#AUDIOFOCUS_NONE} to express that audio focus should not be |
| 271 | * requested when playback starts. You can for instance use this when playing a silent animation |
| 272 | * through this class, and you don't want to affect other audio applications playing in the |
| 273 | * background. |
| 274 | * |
| 275 | * @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^] | 276 | * {@link AudioManager#AUDIOFOCUS_NONE} to disable the use audio focus during |
| 277 | * playback. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 278 | */ |
| 279 | public void setAudioFocusRequest(int focusGain) { |
| 280 | mProvider.setAudioFocusRequest_impl(focusGain); |
| 281 | } |
| 282 | |
| 283 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 284 | * Sets the {@link AudioAttributes} to be used during the playback of the video. |
| 285 | * |
| 286 | * @param attributes non-null <code>AudioAttributes</code>. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 287 | */ |
| 288 | public void setAudioAttributes(@NonNull AudioAttributes attributes) { |
| 289 | mProvider.setAudioAttributes_impl(attributes); |
| 290 | } |
| 291 | |
| 292 | /** |
Sungsoo Lim | af2a1ad | 2018-01-24 11:36:10 +0900 | [diff] [blame^] | 293 | * Sets a remote player for handling playback of the selected route from MediaControlView2. |
| 294 | * If this is not called, MediaCotrolView2 will not show the route button. |
| 295 | * |
| 296 | * @param routeCategories the list of media control categories in |
| 297 | * {@link android.support.v7.media.MediaControlIntent} |
| 298 | * @param player the player to handle the selected route. If null, a default |
| 299 | * route player will be used. |
| 300 | * @throws IllegalStateException if MediaControlView2 is not set. |
| 301 | */ |
| 302 | public void setRouteAttributes(@NonNull List<String> routeCategories, |
| 303 | @Nullable MediaPlayerBase player) { |
| 304 | mProvider.setRouteAttributes_impl(routeCategories, player); |
| 305 | } |
| 306 | |
| 307 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 308 | * Sets video path. |
| 309 | * |
| 310 | * @param path the path of the video. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 311 | */ |
| 312 | public void setVideoPath(String path) { |
| 313 | mProvider.setVideoPath_impl(path); |
| 314 | } |
| 315 | |
| 316 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 317 | * Sets video URI. |
| 318 | * |
| 319 | * @param uri the URI of the video. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 320 | */ |
| 321 | public void setVideoURI(Uri uri) { |
| 322 | mProvider.setVideoURI_impl(uri); |
| 323 | } |
| 324 | |
| 325 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 326 | * Sets video URI using specific headers. |
| 327 | * |
| 328 | * @param uri the URI of the video. |
| 329 | * @param headers the headers for the URI request. |
| 330 | * Note that the cross domain redirection is allowed by default, but that can be |
| 331 | * changed with key/value pairs through the headers parameter with |
| 332 | * "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value |
| 333 | * to disallow or allow cross domain redirection. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 334 | */ |
| 335 | public void setVideoURI(Uri uri, Map<String, String> headers) { |
| 336 | mProvider.setVideoURI_impl(uri, headers); |
| 337 | } |
| 338 | |
| 339 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 340 | * Selects which view will be used to render video between SurfacView and TextureView. |
| 341 | * |
| 342 | * @param viewType the view type to render video |
| 343 | * <ul> |
| 344 | * <li>{@link #VIEW_TYPE_SURFACEVIEW} |
| 345 | * <li>{@link #VIEW_TYPE_TEXTUREVIEW} |
| 346 | * </ul> |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 347 | */ |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 348 | public void setViewType(@ViewType int viewType) { |
| 349 | mProvider.setViewType_impl(viewType); |
| 350 | } |
| 351 | |
| 352 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 353 | * Returns view type. |
| 354 | * |
| 355 | * @return view type. See {@see setViewType}. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 356 | */ |
| 357 | @ViewType |
| 358 | public int getViewType() { |
| 359 | return mProvider.getViewType_impl(); |
| 360 | } |
| 361 | |
| 362 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 363 | * Stops playback and release all the resources. This should be called whenever a VideoView2 |
| 364 | * instance is no longer to be used. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 365 | */ |
| 366 | public void stopPlayback() { |
| 367 | mProvider.stopPlayback_impl(); |
| 368 | } |
| 369 | |
| 370 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 371 | * Registers a callback to be invoked when the media file is loaded and ready to go. |
| 372 | * |
| 373 | * @param l the callback that will be run. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 374 | */ |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 375 | public void setOnPreparedListener(OnPreparedListener l) { |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 376 | mProvider.setOnPreparedListener_impl(l); |
| 377 | } |
| 378 | |
| 379 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 380 | * Registers a callback to be invoked when the end of a media file has been reached during |
| 381 | * playback. |
| 382 | * |
| 383 | * @param l the callback that will be run. |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 384 | */ |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 385 | public void setOnCompletionListener(OnCompletionListener l) { |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 386 | mProvider.setOnCompletionListener_impl(l); |
| 387 | } |
| 388 | |
| 389 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 390 | * Registers a callback to be invoked when an error occurs during playback or setup. If no |
| 391 | * listener is specified, or if the listener returned false, VideoView2 will inform the user of |
| 392 | * any errors. |
| 393 | * |
| 394 | * @param l The callback that will be run |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 395 | */ |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 396 | public void setOnErrorListener(OnErrorListener l) { |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 397 | mProvider.setOnErrorListener_impl(l); |
| 398 | } |
| 399 | |
| 400 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 401 | * Registers a callback to be invoked when an informational event occurs during playback or |
| 402 | * setup. |
| 403 | * |
| 404 | * @param l The callback that will be run |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 405 | */ |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 406 | public void setOnInfoListener(OnInfoListener l) { |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 407 | mProvider.setOnInfoListener_impl(l); |
| 408 | } |
| 409 | |
| 410 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 411 | * Registers a callback to be invoked when a view type change is done. |
| 412 | * {@see #setViewType(int)} |
| 413 | * @param l The callback that will be run |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 414 | */ |
| 415 | public void setOnViewTypeChangedListener(OnViewTypeChangedListener l) { |
| 416 | mProvider.setOnViewTypeChangedListener_impl(l); |
| 417 | } |
| 418 | |
| 419 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 420 | * 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] | 421 | */ |
| 422 | public interface OnViewTypeChangedListener { |
| 423 | /** |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 424 | * Called when the view type has been changed. |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 425 | * @see #setViewType(int) |
| 426 | * @param viewType |
| 427 | * <ul> |
| 428 | * <li>{@link #VIEW_TYPE_SURFACEVIEW} |
| 429 | * <li>{@link #VIEW_TYPE_TEXTUREVIEW} |
| 430 | * </ul> |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 431 | */ |
| 432 | void onViewTypeChanged(@ViewType int viewType); |
| 433 | } |
| 434 | |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 435 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 436 | * 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] | 437 | */ |
| 438 | public interface OnPreparedListener { |
| 439 | /** |
| 440 | * Called when the media file is ready for playback. |
| 441 | */ |
| 442 | void onPrepared(); |
| 443 | } |
| 444 | |
| 445 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 446 | * Interface definition for a callback to be invoked when playback of a media source has |
| 447 | * completed. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 448 | */ |
| 449 | public interface OnCompletionListener { |
| 450 | /** |
| 451 | * Called when the end of a media source is reached during playback. |
| 452 | */ |
| 453 | void onCompletion(); |
| 454 | } |
| 455 | |
| 456 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 457 | * Interface definition of a callback to be invoked when there has been an error during an |
| 458 | * asynchronous operation. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 459 | */ |
| 460 | public interface OnErrorListener { |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 461 | // TODO: Redefine error codes. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 462 | /** |
| 463 | * Called to indicate an error. |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 464 | * @param what the type of error that has occurred |
| 465 | * @param extra an extra code, specific to the error. |
| 466 | * @return true if the method handled the error, false if it didn't. |
| 467 | * @see MediaPlayer#OnErrorListener |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 468 | */ |
| 469 | boolean onError(int what, int extra); |
| 470 | } |
| 471 | |
| 472 | /** |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 473 | * Interface definition of a callback to be invoked to communicate some info and/or warning |
| 474 | * about the media or its playback. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 475 | */ |
| 476 | public interface OnInfoListener { |
| 477 | /** |
| 478 | * Called to indicate an info or a warning. |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 479 | * @param what the type of info or warning. |
| 480 | * @param extra an extra code, specific to the info. |
Insun Kang | eb78d51 | 2018-01-22 18:04:07 +0900 | [diff] [blame] | 481 | * |
| 482 | * @see MediaPlayer#OnInfoListener |
Insun Kang | de16c4d | 2018-01-17 23:06:18 +0900 | [diff] [blame] | 483 | */ |
| 484 | void onInfo(int what, int extra); |
| 485 | } |
| 486 | |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 487 | @Override |
Insun Kang | fd3fdfd | 2018-01-23 15:01:37 +0900 | [diff] [blame] | 488 | protected void onAttachedToWindow() { |
| 489 | mProvider.onAttachedToWindow_impl(); |
| 490 | } |
| 491 | |
| 492 | @Override |
| 493 | protected void onDetachedFromWindow() { |
| 494 | mProvider.onDetachedFromWindow_impl(); |
| 495 | } |
| 496 | |
| 497 | @Override |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 498 | public CharSequence getAccessibilityClassName() { |
| 499 | return mProvider.getAccessibilityClassName_impl(); |
| 500 | } |
| 501 | |
| 502 | @Override |
| 503 | public boolean onTouchEvent(MotionEvent ev) { |
| 504 | return mProvider.onTouchEvent_impl(ev); |
| 505 | } |
| 506 | |
| 507 | @Override |
| 508 | public boolean onTrackballEvent(MotionEvent ev) { |
| 509 | return mProvider.onTrackballEvent_impl(ev); |
| 510 | } |
| 511 | |
| 512 | @Override |
| 513 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 514 | return mProvider.onKeyDown_impl(keyCode, event); |
| 515 | } |
| 516 | |
| 517 | @Override |
| 518 | public void onFinishInflate() { |
| 519 | mProvider.onFinishInflate_impl(); |
| 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 524 | return mProvider.dispatchKeyEvent_impl(event); |
| 525 | } |
| 526 | |
| 527 | @Override |
| 528 | public void setEnabled(boolean enabled) { |
| 529 | mProvider.setEnabled_impl(enabled); |
| 530 | } |
| 531 | |
| 532 | private class SuperProvider implements ViewProvider { |
| 533 | @Override |
Insun Kang | fd3fdfd | 2018-01-23 15:01:37 +0900 | [diff] [blame] | 534 | public void onAttachedToWindow_impl() { |
| 535 | VideoView2.super.onAttachedToWindow(); |
| 536 | } |
| 537 | |
| 538 | @Override |
| 539 | public void onDetachedFromWindow_impl() { |
| 540 | VideoView2.super.onDetachedFromWindow(); |
| 541 | } |
| 542 | |
| 543 | @Override |
Sungsoo Lim | e325904 | 2018-01-16 09:25:28 +0900 | [diff] [blame] | 544 | public CharSequence getAccessibilityClassName_impl() { |
| 545 | return VideoView2.super.getAccessibilityClassName(); |
| 546 | } |
| 547 | |
| 548 | @Override |
| 549 | public boolean onTouchEvent_impl(MotionEvent ev) { |
| 550 | return VideoView2.super.onTouchEvent(ev); |
| 551 | } |
| 552 | |
| 553 | @Override |
| 554 | public boolean onTrackballEvent_impl(MotionEvent ev) { |
| 555 | return VideoView2.super.onTrackballEvent(ev); |
| 556 | } |
| 557 | |
| 558 | @Override |
| 559 | public boolean onKeyDown_impl(int keyCode, KeyEvent event) { |
| 560 | return VideoView2.super.onKeyDown(keyCode, event); |
| 561 | } |
| 562 | |
| 563 | @Override |
| 564 | public void onFinishInflate_impl() { |
| 565 | VideoView2.super.onFinishInflate(); |
| 566 | } |
| 567 | |
| 568 | @Override |
| 569 | public boolean dispatchKeyEvent_impl(KeyEvent event) { |
| 570 | return VideoView2.super.dispatchKeyEvent(event); |
| 571 | } |
| 572 | |
| 573 | @Override |
| 574 | public void setEnabled_impl(boolean enabled) { |
| 575 | VideoView2.super.setEnabled(enabled); |
| 576 | } |
| 577 | } |
| 578 | } |