VideoView2.java revision 682483d1652bda42e653ea8aa4cbb9f8572c53e7
1e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim/* 2e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * Copyright 2018 The Android Open Source Project 3e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * 4e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * Licensed under the Apache License, Version 2.0 (the "License"); 5e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * you may not use this file except in compliance with the License. 6e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * You may obtain a copy of the License at 7e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * 8e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * http://www.apache.org/licenses/LICENSE-2.0 9e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * 10e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * Unless required by applicable law or agreed to in writing, software 11e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * distributed under the License is distributed on an "AS IS" BASIS, 12e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * See the License for the specific language governing permissions and 14e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * limitations under the License. 15e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 16e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 17e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limpackage android.widget; 18e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 19e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport android.annotation.IntDef; 20e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport android.annotation.NonNull; 21e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport android.annotation.Nullable; 22e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport android.content.Context; 23e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport android.media.AudioAttributes; 24de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kangimport android.media.AudioManager; 251a2c263c7a60235fc3001d4699f2cac9cd02beb7Jaewan Kimimport android.media.MediaPlayerInterface; 2682af545ca64bff030697a0369e0301c03e8123ecSungsoo Limimport android.media.session.MediaController; 27d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Limimport android.media.session.MediaSession; 2846377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moonimport android.media.session.PlaybackState; 29e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport android.media.update.ApiLoader; 30e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport android.media.update.VideoView2Provider; 31f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kerstenimport android.media.update.ViewGroupHelper; 32e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport android.net.Uri; 3346377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moonimport android.os.Bundle; 34e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport android.util.AttributeSet; 35df0728c15af0f6cc101883af097ffe680279448aInsun Kangimport android.view.View; 36e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 37e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport java.lang.annotation.Retention; 38e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport java.lang.annotation.RetentionPolicy; 39af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Limimport java.util.List; 40e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport java.util.Map; 41620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kangimport java.util.concurrent.Executor; 42e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 43620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang// TODO: Replace MediaSession wtih MediaSession2 once MediaSession2 is submitted. 44e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim/** 45eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Displays a video file. VideoView2 class is a View class which is wrapping MediaPlayer2 so that 46eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * developers can easily implement a video rendering application. 47eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 48eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 49eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <em> Data sources that VideoView2 supports : </em> 50df0728c15af0f6cc101883af097ffe680279448aInsun Kang * VideoView2 can play video files and audio-only files as 51eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * well. It can load from various sources such as resources or content providers. The supported 52eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * media file formats are the same as MediaPlayer2. 53eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 54eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 55eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <em> View type can be selected : </em> 56eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * VideoView2 can render videos on top of TextureView as well as 57eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * SurfaceView selectively. The default is SurfaceView and it can be changed using 58eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link #setViewType(int)} method. Using SurfaceView is recommended in most cases for saving 59eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * battery. TextureView might be preferred for supporting various UIs such as animation and 60eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * translucency. 61eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 62eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 63eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <em> Differences between {@link VideoView} class : </em> 64eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * VideoView2 covers and inherits the most of 65eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * VideoView's functionalities. The main differences are 66eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <ul> 67eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li> VideoView2 inherits FrameLayout and renders videos using SurfaceView and TextureView 68eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * selectively while VideoView inherits SurfaceView class. 69eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li> VideoView2 is integrated with MediaControlView2 and a default MediaControlView2 instance is 70eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * attached to VideoView2 by default. If a developer does not want to use the default 71eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * MediaControlView2, needs to set enableControlView attribute to false. For instance, 72eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <pre> 73eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <VideoView2 74eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * android:id="@+id/video_view" 75eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * xmlns:widget="http://schemas.android.com/apk/com.android.media.update" 76eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * widget:enableControlView="false" /> 77eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </pre> 78eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * If a developer wants to attach a customed MediaControlView2, then set enableControlView attribute 79eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * to false and assign the customed media control widget using {@link #setMediaControlView2}. 80eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li> VideoView2 is integrated with MediaPlayer2 while VideoView is integrated with MediaPlayer. 8182af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * <li> VideoView2 is integrated with MediaSession and so it responses with media key events. 8282af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * A VideoView2 keeps a MediaSession instance internally and connects it to a corresponding 83eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * MediaControlView2 instance. 84eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </p> 85eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </ul> 86eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 87eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 88eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <em> Audio focus and audio attributes : </em> 89eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * By default, VideoView2 requests audio focus with 90eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link AudioManager#AUDIOFOCUS_GAIN}. Use {@link #setAudioFocusRequest(int)} to change this 91eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * behavior. The default {@link AudioAttributes} used during playback have a usage of 92eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link AudioAttributes#USAGE_MEDIA} and a content type of 93eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link AudioAttributes#CONTENT_TYPE_MOVIE}, use {@link #setAudioAttributes(AudioAttributes)} to 94eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * modify them. 95eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 96eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 97eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Note: VideoView2 does not retain its full state when going into the background. In particular, it 98eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * does not restore the current play state, play position, selected tracks. Applications should save 99eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * and restore these on their own in {@link android.app.Activity#onSaveInstanceState} and 100eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link android.app.Activity#onRestoreInstanceState}. 101eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 102e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * @hide 103e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 104f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kerstenpublic class VideoView2 extends ViewGroupHelper<VideoView2Provider> { 105eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang /** @hide */ 106e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim @IntDef({ 107e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim VIEW_TYPE_TEXTUREVIEW, 108e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim VIEW_TYPE_SURFACEVIEW 109e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim }) 110e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim @Retention(RetentionPolicy.SOURCE) 111e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public @interface ViewType {} 112eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang 113df0728c15af0f6cc101883af097ffe680279448aInsun Kang /** 1144fa8064378770a0e05b7462c173bfb74cb540f37Insun Kang * Indicates video is rendering on SurfaceView. 115df0728c15af0f6cc101883af097ffe680279448aInsun Kang * 116df0728c15af0f6cc101883af097ffe680279448aInsun Kang * @see #setViewType 117df0728c15af0f6cc101883af097ffe680279448aInsun Kang */ 118e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public static final int VIEW_TYPE_SURFACEVIEW = 1; 119df0728c15af0f6cc101883af097ffe680279448aInsun Kang 120df0728c15af0f6cc101883af097ffe680279448aInsun Kang /** 1214fa8064378770a0e05b7462c173bfb74cb540f37Insun Kang * Indicates video is rendering on TextureView. 122df0728c15af0f6cc101883af097ffe680279448aInsun Kang * 123df0728c15af0f6cc101883af097ffe680279448aInsun Kang * @see #setViewType 124df0728c15af0f6cc101883af097ffe680279448aInsun Kang */ 125e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public static final int VIEW_TYPE_TEXTUREVIEW = 2; 126e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 127e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public VideoView2(@NonNull Context context) { 128e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim this(context, null); 129e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 130e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 131e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs) { 132e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim this(context, attrs, 0); 133e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 134e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 135e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 136e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim this(context, attrs, defStyleAttr, 0); 137e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 138e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 139e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public VideoView2( 140e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim @NonNull Context context, @Nullable AttributeSet attrs, 141e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim int defStyleAttr, int defStyleRes) { 142f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kersten super((instance, superProvider, privateProvider) -> 143a6c97e4615890f491f14f22409657b7b7d723dabChristofer Ã…kersten ApiLoader.getProvider(context).createVideoView2( 144f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kersten (VideoView2) instance, superProvider, privateProvider, 145f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kersten attrs, defStyleAttr, defStyleRes), 146a6c97e4615890f491f14f22409657b7b7d723dabChristofer Ã…kersten context, attrs, defStyleAttr, defStyleRes); 147f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kersten mProvider.initialize(attrs, defStyleAttr, defStyleRes); 148e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 149e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 150e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 151eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Sets MediaControlView2 instance. It will replace the previously assigned MediaControlView2 152eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * instance if any. 153eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 154eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param mediaControlView a media control view2 instance. 155e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 156de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang public void setMediaControlView2(MediaControlView2 mediaControlView) { 157de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang mProvider.setMediaControlView2_impl(mediaControlView); 158de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 159de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 160de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 161eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Returns MediaControlView2 instance which is currently attached to VideoView2 by default or by 162eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link #setMediaControlView2} method. 163de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 164de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang public MediaControlView2 getMediaControlView2() { 165de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang return mProvider.getMediaControlView2_impl(); 166de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 167de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 168e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 169e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 17082af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * Returns MediaController instance which is connected with MediaSession that VideoView2 is 17182af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * using. This method should be called when VideoView2 is attached to window, or it throws 17282af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * IllegalStateException, since internal MediaSession instance is not available until 17382af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * this view is attached to window. Please check {@link android.view.View#isAttachedToWindow} 17482af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * before calling this method. 17582af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * 17682af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * @throws IllegalStateException if interal MediaSession is not created yet. 177e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 17882af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim public MediaController getMediaController() { 17982af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim return mProvider.getMediaController_impl(); 180e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 181e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 182e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 1834fa8064378770a0e05b7462c173bfb74cb540f37Insun Kang * Shows or hides closed caption or subtitles if there is any. 184682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * The first subtitle track will be chosen if there multiple subtitle tracks exist. 185682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * Default behavior of VideoView2 is not showing subtitle. 186682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * @param enable shows closed caption or subtitles if this value is true, or hides. 187e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 188682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang public void setSubtitleEnabled(boolean enable) { 189682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang mProvider.setSubtitleEnabled_impl(enable); 190682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang } 191682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang 192682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang /** 193682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * Returns true if showing subtitle feature is enabled or returns false. 194682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * Although there is no subtitle track or closed caption, it can return true, if the feature 195682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * has been enabled by {@link #setSubtitleEnabled}. 196682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang */ 197682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang public boolean isSubtitleEnabled() { 198682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang return mProvider.isSubtitleEnabled_impl(); 199e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 200e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 201efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon /** 202de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Sets playback speed. 203de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * 204de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * It is expressed as a multiplicative factor, where normal speed is 1.0f. If it is less than 205de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * or equal to zero, it will be just ignored and nothing will be changed. If it exceeds the 206de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * maximum speed that internal engine supports, system will determine best handling or it will 207de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * be reset to the normal speed 1.0f. 208de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param speed the playback speed. It should be positive. 209de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 21082af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim // TODO: Support this via MediaController2. 211de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang public void setSpeed(float speed) { 212de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang mProvider.setSpeed_impl(speed); 213de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 214de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 215de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 216de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Sets which type of audio focus will be requested during the playback, or configures playback 217de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * to not request audio focus. Valid values for focus requests are 218de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * {@link AudioManager#AUDIOFOCUS_GAIN}, {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT}, 219de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK}, and 220de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}. Or use 221de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * {@link AudioManager#AUDIOFOCUS_NONE} to express that audio focus should not be 222de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * requested when playback starts. You can for instance use this when playing a silent animation 223de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * through this class, and you don't want to affect other audio applications playing in the 224de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * background. 225de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * 226de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param focusGain the type of audio focus gain that will be requested, or 227af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * {@link AudioManager#AUDIOFOCUS_NONE} to disable the use audio focus during 228af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * playback. 229e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 230e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public void setAudioFocusRequest(int focusGain) { 231e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim mProvider.setAudioFocusRequest_impl(focusGain); 232e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 233e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 234e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 235de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Sets the {@link AudioAttributes} to be used during the playback of the video. 236de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * 237de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param attributes non-null <code>AudioAttributes</code>. 238e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 239e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public void setAudioAttributes(@NonNull AudioAttributes attributes) { 240e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim mProvider.setAudioAttributes_impl(attributes); 241e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 242e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 243e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 244af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * Sets a remote player for handling playback of the selected route from MediaControlView2. 245af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * If this is not called, MediaCotrolView2 will not show the route button. 246af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * 247af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * @param routeCategories the list of media control categories in 248af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * {@link android.support.v7.media.MediaControlIntent} 249d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @param player the player to handle playback of the selected route. 250d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * If null, a default route player will be used. 251af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * @throws IllegalStateException if MediaControlView2 is not set. 252d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @hide 253af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim */ 254af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim public void setRouteAttributes(@NonNull List<String> routeCategories, 2551a2c263c7a60235fc3001d4699f2cac9cd02beb7Jaewan Kim @Nullable MediaPlayerInterface player) { 256af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim mProvider.setRouteAttributes_impl(routeCategories, player); 257af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim } 258af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim 259af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim /** 260d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * Sets a remote player for handling playback of the selected route from MediaControlView2. 261d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * If this is not called, MediaCotrolView2 will not show the route button. 262d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * 263d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @param routeCategories the list of media control categories in 264d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * {@link android.support.v7.media.MediaControlIntent} 265d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @param sessionPlayer the player to handle playback of the selected route. 266d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * If null, a default route player will be used. 267d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @throws IllegalStateException if MediaControlView2 is not set. 268d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @hide 269d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim */ 270d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim // TODO: Use MediaPlayerBase once MediaSession2 APIs are ready. 271d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim public void setRouteAttributes(@NonNull List<String> routeCategories, 272d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim @Nullable MediaSession.Callback sessionPlayer) { 273d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim mProvider.setRouteAttributes_impl(routeCategories, sessionPlayer); 274d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim } 275d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim 276d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim /** 277de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Sets video path. 278de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * 279de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param path the path of the video. 280e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 281e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public void setVideoPath(String path) { 282e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim mProvider.setVideoPath_impl(path); 283e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 284e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 285e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 286eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Sets video URI. 287eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 288eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param uri the URI of the video. 289e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 290df0728c15af0f6cc101883af097ffe680279448aInsun Kang public void setVideoUri(Uri uri) { 291df0728c15af0f6cc101883af097ffe680279448aInsun Kang mProvider.setVideoUri_impl(uri); 292e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 293e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 294e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 295eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Sets video URI using specific headers. 296eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 297eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param uri the URI of the video. 298eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param headers the headers for the URI request. 299eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Note that the cross domain redirection is allowed by default, but that can be 300eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * changed with key/value pairs through the headers parameter with 301eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value 302eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * to disallow or allow cross domain redirection. 303e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 304df0728c15af0f6cc101883af097ffe680279448aInsun Kang public void setVideoUri(Uri uri, Map<String, String> headers) { 305df0728c15af0f6cc101883af097ffe680279448aInsun Kang mProvider.setVideoUri_impl(uri, headers); 306e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 307e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 308e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 309eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Selects which view will be used to render video between SurfacView and TextureView. 310eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 311eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param viewType the view type to render video 312eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <ul> 313eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li>{@link #VIEW_TYPE_SURFACEVIEW} 314eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li>{@link #VIEW_TYPE_TEXTUREVIEW} 315eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </ul> 316e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 317e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public void setViewType(@ViewType int viewType) { 318e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim mProvider.setViewType_impl(viewType); 319e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 320e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 321e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 322eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Returns view type. 323eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 324eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @return view type. See {@see setViewType}. 325e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 326e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim @ViewType 327e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public int getViewType() { 328e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim return mProvider.getViewType_impl(); 329e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 330e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 331e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 33246377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * Sets custom actions which will be shown as custom buttons in {@link MediaControlView2}. 33346377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * 33446377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * @param actionList A list of {@link PlaybackState.CustomAction}. The return value of 33546377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * {@link PlaybackState.CustomAction#getIcon()} will be used to draw buttons 33646377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * in {@link MediaControlView2}. 337620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param executor executor to run callbacks on. 33846377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * @param listener A listener to be called when a custom button is clicked. 33946377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon */ 34046377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon public void setCustomActions(List<PlaybackState.CustomAction> actionList, 341620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang Executor executor, OnCustomActionListener listener) { 342620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang mProvider.setCustomActions_impl(actionList, executor, listener); 34346377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon } 34446377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon 34546377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon /** 346eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Registers a callback to be invoked when the media file is loaded and ready to go. 347eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 348620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param executor executor to run callbacks on. 349eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param l the callback that will be run. 350e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 351620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang public void setOnPreparedListener(Executor executor, OnPreparedListener l) { 352620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang mProvider.setOnPreparedListener_impl(executor, l); 353e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 354e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 355e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 356eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Registers a callback to be invoked when the end of a media file has been reached during 357eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * playback. 358eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 359620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param executor executor to run callbacks on. 360eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param l the callback that will be run. 361e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 362620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang public void setOnCompletionListener(Executor executor, OnCompletionListener l) { 363620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang mProvider.setOnCompletionListener_impl(executor, l); 364e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 365e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 366e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 367eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Registers a callback to be invoked when an error occurs during playback or setup. If no 368eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * listener is specified, or if the listener returned false, VideoView2 will inform the user of 369eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * any errors. 370eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 371620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param executor executor to run callbacks on. 372eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param l The callback that will be run 373e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 374620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang public void setOnErrorListener(Executor executor, OnErrorListener l) { 375620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang mProvider.setOnErrorListener_impl(executor, l); 376e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 377e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 378e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 379eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Registers a callback to be invoked when an informational event occurs during playback or 380eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * setup. 381eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 382620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param executor executor to run callbacks on. 383eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param l The callback that will be run 384e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 385620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang public void setOnInfoListener(Executor executor, OnInfoListener l) { 386620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang mProvider.setOnInfoListener_impl(executor, l); 387e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 388e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 389e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 390eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Registers a callback to be invoked when a view type change is done. 391eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@see #setViewType(int)} 392620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param executor executor to run callbacks on. 393eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param l The callback that will be run 394e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 395620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang public void setOnViewTypeChangedListener(Executor executor, OnViewTypeChangedListener l) { 396620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang mProvider.setOnViewTypeChangedListener_impl(executor, l); 397e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 398e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 399e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 400efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon * Registers a callback to be invoked when the fullscreen mode should be changed. 401620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param executor executor to run callbacks on. 402620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param l The callback that will be run 403efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon */ 404620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang public void setFullScreenRequestListener(Executor executor, OnFullScreenRequestListener l) { 405620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang mProvider.setFullScreenRequestListener_impl(executor, l); 406efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon } 407efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon 408efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon /** 409df0728c15af0f6cc101883af097ffe680279448aInsun Kang * Interface definition of a callback to be invoked when the view type has been changed. 410e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 411e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public interface OnViewTypeChangedListener { 412e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 413de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Called when the view type has been changed. 414eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @see #setViewType(int) 415df0728c15af0f6cc101883af097ffe680279448aInsun Kang * @param view the View whose view type is changed 416eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param viewType 417eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <ul> 418eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li>{@link #VIEW_TYPE_SURFACEVIEW} 419eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li>{@link #VIEW_TYPE_TEXTUREVIEW} 420eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </ul> 421e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 422df0728c15af0f6cc101883af097ffe680279448aInsun Kang void onViewTypeChanged(View view, @ViewType int viewType); 423e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 424e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 425de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 426eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Interface definition of a callback to be invoked when the media source is ready for playback. 427de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 428de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang public interface OnPreparedListener { 429de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 430de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Called when the media file is ready for playback. 431de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 432df0728c15af0f6cc101883af097ffe680279448aInsun Kang void onPrepared(View view); 433de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 434de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 435de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 436eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Interface definition for a callback to be invoked when playback of a media source has 437eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * completed. 438de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 439de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang public interface OnCompletionListener { 440de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 441de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Called when the end of a media source is reached during playback. 442de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 443df0728c15af0f6cc101883af097ffe680279448aInsun Kang void onCompletion(View view); 444de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 445de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 446de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 447eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Interface definition of a callback to be invoked when there has been an error during an 448eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * asynchronous operation. 449de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 450de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang public interface OnErrorListener { 451eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang // TODO: Redefine error codes. 452de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 453de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Called to indicate an error. 454eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param what the type of error that has occurred 455eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param extra an extra code, specific to the error. 456eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @return true if the method handled the error, false if it didn't. 457eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @see MediaPlayer#OnErrorListener 458de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 459df0728c15af0f6cc101883af097ffe680279448aInsun Kang boolean onError(View view, int what, int extra); 460de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 461de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 462de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 463eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Interface definition of a callback to be invoked to communicate some info and/or warning 464eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * about the media or its playback. 465de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 466de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang public interface OnInfoListener { 467de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 468de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Called to indicate an info or a warning. 469de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param what the type of info or warning. 470de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param extra an extra code, specific to the info. 471eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 472eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @see MediaPlayer#OnInfoListener 473de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 474df0728c15af0f6cc101883af097ffe680279448aInsun Kang void onInfo(View view, int what, int extra); 475de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 476de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 477efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon /** 478efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon * Interface definition of a callback to be invoked to inform the fullscreen mode is changed. 479620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * Application should handle the fullscreen mode accordingly. 480efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon */ 481620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang public interface OnFullScreenRequestListener { 482efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon /** 483efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon * Called to indicate a fullscreen mode change. 484efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon */ 485620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang void onFullScreenRequest(View view, boolean fullScreen); 486efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon } 487efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon 48846377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon /** 48946377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * Interface definition of a callback to be invoked to inform that a custom action is performed. 49046377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon */ 491620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang // TODO: When MediaSession2 is ready, modify the method to match the signature. 49246377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon public interface OnCustomActionListener { 49346377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon /** 49446377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * Called to indicate that a custom action is performed. 49546377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * 49646377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * @param action The action that was originally sent in the 49746377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * {@link PlaybackState.CustomAction}. 49846377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * @param extras Optional extras. 49946377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon */ 50046377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon void onCustomAction(String action, Bundle extras); 50146377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon } 5028589b7b34bd79d74ad4af218c162f63650161882Insun Kang 5038589b7b34bd79d74ad4af218c162f63650161882Insun Kang @Override 5048589b7b34bd79d74ad4af218c162f63650161882Insun Kang protected void onLayout(boolean changed, int l, int t, int r, int b) { 5058589b7b34bd79d74ad4af218c162f63650161882Insun Kang mProvider.onLayout_impl(changed, l, t, r, b); 5068589b7b34bd79d74ad4af218c162f63650161882Insun Kang } 507e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim} 508