VideoView2.java revision a35d1b194696ff73970b640446b2391711ea6030
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 37a35d1b194696ff73970b640446b2391711ea6030Insun Kangimport com.android.internal.annotations.VisibleForTesting; 38a35d1b194696ff73970b640446b2391711ea6030Insun Kang 39e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport java.lang.annotation.Retention; 40e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport java.lang.annotation.RetentionPolicy; 41af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Limimport java.util.List; 42e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Limimport java.util.Map; 43620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kangimport java.util.concurrent.Executor; 44e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 45620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang// TODO: Replace MediaSession wtih MediaSession2 once MediaSession2 is submitted. 46e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim/** 47eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Displays a video file. VideoView2 class is a View class which is wrapping MediaPlayer2 so that 48eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * developers can easily implement a video rendering application. 49eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 50eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 51eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <em> Data sources that VideoView2 supports : </em> 52df0728c15af0f6cc101883af097ffe680279448aInsun Kang * VideoView2 can play video files and audio-only files as 53eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * well. It can load from various sources such as resources or content providers. The supported 54eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * media file formats are the same as MediaPlayer2. 55eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 56eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 57eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <em> View type can be selected : </em> 58eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * VideoView2 can render videos on top of TextureView as well as 59eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * SurfaceView selectively. The default is SurfaceView and it can be changed using 60eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link #setViewType(int)} method. Using SurfaceView is recommended in most cases for saving 61eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * battery. TextureView might be preferred for supporting various UIs such as animation and 62eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * translucency. 63eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 64eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 65eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <em> Differences between {@link VideoView} class : </em> 66eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * VideoView2 covers and inherits the most of 67eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * VideoView's functionalities. The main differences are 68eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <ul> 69eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li> VideoView2 inherits FrameLayout and renders videos using SurfaceView and TextureView 70eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * selectively while VideoView inherits SurfaceView class. 71eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li> VideoView2 is integrated with MediaControlView2 and a default MediaControlView2 instance is 72eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * attached to VideoView2 by default. If a developer does not want to use the default 73eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * MediaControlView2, needs to set enableControlView attribute to false. For instance, 74eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <pre> 75eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <VideoView2 76eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * android:id="@+id/video_view" 77eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * xmlns:widget="http://schemas.android.com/apk/com.android.media.update" 78eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * widget:enableControlView="false" /> 79eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </pre> 80eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * If a developer wants to attach a customed MediaControlView2, then set enableControlView attribute 81eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * to false and assign the customed media control widget using {@link #setMediaControlView2}. 82eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li> VideoView2 is integrated with MediaPlayer2 while VideoView is integrated with MediaPlayer. 8382af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * <li> VideoView2 is integrated with MediaSession and so it responses with media key events. 8482af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * A VideoView2 keeps a MediaSession instance internally and connects it to a corresponding 85eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * MediaControlView2 instance. 86eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </p> 87eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </ul> 88eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 89eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 90eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <em> Audio focus and audio attributes : </em> 91eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * By default, VideoView2 requests audio focus with 92eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link AudioManager#AUDIOFOCUS_GAIN}. Use {@link #setAudioFocusRequest(int)} to change this 93eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * behavior. The default {@link AudioAttributes} used during playback have a usage of 94eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link AudioAttributes#USAGE_MEDIA} and a content type of 95eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link AudioAttributes#CONTENT_TYPE_MOVIE}, use {@link #setAudioAttributes(AudioAttributes)} to 96eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * modify them. 97eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 98eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <p> 99eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Note: VideoView2 does not retain its full state when going into the background. In particular, it 100eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * does not restore the current play state, play position, selected tracks. Applications should save 101eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * and restore these on their own in {@link android.app.Activity#onSaveInstanceState} and 102eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link android.app.Activity#onRestoreInstanceState}. 103eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 104e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim * @hide 105e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 106f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kerstenpublic class VideoView2 extends ViewGroupHelper<VideoView2Provider> { 107eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang /** @hide */ 108e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim @IntDef({ 109e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim VIEW_TYPE_TEXTUREVIEW, 110e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim VIEW_TYPE_SURFACEVIEW 111e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim }) 112e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim @Retention(RetentionPolicy.SOURCE) 113e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public @interface ViewType {} 114eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang 115df0728c15af0f6cc101883af097ffe680279448aInsun Kang /** 1164fa8064378770a0e05b7462c173bfb74cb540f37Insun Kang * Indicates video is rendering on SurfaceView. 117df0728c15af0f6cc101883af097ffe680279448aInsun Kang * 118df0728c15af0f6cc101883af097ffe680279448aInsun Kang * @see #setViewType 119df0728c15af0f6cc101883af097ffe680279448aInsun Kang */ 120e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public static final int VIEW_TYPE_SURFACEVIEW = 1; 121df0728c15af0f6cc101883af097ffe680279448aInsun Kang 122df0728c15af0f6cc101883af097ffe680279448aInsun Kang /** 1234fa8064378770a0e05b7462c173bfb74cb540f37Insun Kang * Indicates video is rendering on TextureView. 124df0728c15af0f6cc101883af097ffe680279448aInsun Kang * 125df0728c15af0f6cc101883af097ffe680279448aInsun Kang * @see #setViewType 126df0728c15af0f6cc101883af097ffe680279448aInsun Kang */ 127e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public static final int VIEW_TYPE_TEXTUREVIEW = 2; 128e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 129e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public VideoView2(@NonNull Context context) { 130e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim this(context, null); 131e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 132e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 133e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs) { 134e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim this(context, attrs, 0); 135e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 136e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 137e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 138e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim this(context, attrs, defStyleAttr, 0); 139e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 140e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 141e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public VideoView2( 142e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim @NonNull Context context, @Nullable AttributeSet attrs, 143e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim int defStyleAttr, int defStyleRes) { 144f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kersten super((instance, superProvider, privateProvider) -> 145a6c97e4615890f491f14f22409657b7b7d723dabChristofer Ã…kersten ApiLoader.getProvider(context).createVideoView2( 146f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kersten (VideoView2) instance, superProvider, privateProvider, 147f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kersten attrs, defStyleAttr, defStyleRes), 148a6c97e4615890f491f14f22409657b7b7d723dabChristofer Ã…kersten context, attrs, defStyleAttr, defStyleRes); 149f38d8fb9344954ed28ccaaee8e29dcd4d65f1fe0Christofer Ã…kersten mProvider.initialize(attrs, defStyleAttr, defStyleRes); 150e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 151e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 152e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 153eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Sets MediaControlView2 instance. It will replace the previously assigned MediaControlView2 154eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * instance if any. 155eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 156eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param mediaControlView a media control view2 instance. 157718c1d122f66ee0b95b8d7cc7f2988730d73461eInsun Kang * @param intervalMs a time interval in milliseconds until VideoView2 hides MediaControlView2. 158e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 159718c1d122f66ee0b95b8d7cc7f2988730d73461eInsun Kang public void setMediaControlView2(MediaControlView2 mediaControlView, long intervalMs) { 160718c1d122f66ee0b95b8d7cc7f2988730d73461eInsun Kang mProvider.setMediaControlView2_impl(mediaControlView, intervalMs); 161de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 162de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 163de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 164eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Returns MediaControlView2 instance which is currently attached to VideoView2 by default or by 165eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@link #setMediaControlView2} method. 166de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 167de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang public MediaControlView2 getMediaControlView2() { 168de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang return mProvider.getMediaControlView2_impl(); 169de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 170de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 171e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 172e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 17382af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * Returns MediaController instance which is connected with MediaSession that VideoView2 is 17482af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * using. This method should be called when VideoView2 is attached to window, or it throws 17582af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * IllegalStateException, since internal MediaSession instance is not available until 17682af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * this view is attached to window. Please check {@link android.view.View#isAttachedToWindow} 17782af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * before calling this method. 17882af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * 17982af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim * @throws IllegalStateException if interal MediaSession is not created yet. 180e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 18182af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim public MediaController getMediaController() { 18282af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim return mProvider.getMediaController_impl(); 183e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 184e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 185e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 1864fa8064378770a0e05b7462c173bfb74cb540f37Insun Kang * Shows or hides closed caption or subtitles if there is any. 187682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * The first subtitle track will be chosen if there multiple subtitle tracks exist. 188682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * Default behavior of VideoView2 is not showing subtitle. 189682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * @param enable shows closed caption or subtitles if this value is true, or hides. 190e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 191682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang public void setSubtitleEnabled(boolean enable) { 192682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang mProvider.setSubtitleEnabled_impl(enable); 193682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang } 194682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang 195682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang /** 196682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * Returns true if showing subtitle feature is enabled or returns false. 197682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * Although there is no subtitle track or closed caption, it can return true, if the feature 198682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang * has been enabled by {@link #setSubtitleEnabled}. 199682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang */ 200682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang public boolean isSubtitleEnabled() { 201682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang return mProvider.isSubtitleEnabled_impl(); 202e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 203e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 204efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon /** 205de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Sets playback speed. 206de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * 207de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * It is expressed as a multiplicative factor, where normal speed is 1.0f. If it is less than 208de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * or equal to zero, it will be just ignored and nothing will be changed. If it exceeds the 209de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * maximum speed that internal engine supports, system will determine best handling or it will 210de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * be reset to the normal speed 1.0f. 211de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param speed the playback speed. It should be positive. 212de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang */ 21382af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim // TODO: Support this via MediaController2. 214de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang public void setSpeed(float speed) { 215de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang mProvider.setSpeed_impl(speed); 216de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang } 217de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang 218de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 219de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Sets which type of audio focus will be requested during the playback, or configures playback 220de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * to not request audio focus. Valid values for focus requests are 221de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * {@link AudioManager#AUDIOFOCUS_GAIN}, {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT}, 222de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK}, and 223de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}. Or use 224de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * {@link AudioManager#AUDIOFOCUS_NONE} to express that audio focus should not be 225de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * requested when playback starts. You can for instance use this when playing a silent animation 226de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * through this class, and you don't want to affect other audio applications playing in the 227de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * background. 228de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * 229de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param focusGain the type of audio focus gain that will be requested, or 230af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * {@link AudioManager#AUDIOFOCUS_NONE} to disable the use audio focus during 231af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * playback. 232e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 233e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public void setAudioFocusRequest(int focusGain) { 234e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim mProvider.setAudioFocusRequest_impl(focusGain); 235e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 236e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 237e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 238de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Sets the {@link AudioAttributes} to be used during the playback of the video. 239de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * 240de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param attributes non-null <code>AudioAttributes</code>. 241e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 242e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public void setAudioAttributes(@NonNull AudioAttributes attributes) { 243e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim mProvider.setAudioAttributes_impl(attributes); 244e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 245e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 246e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 247af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * Sets a remote player for handling playback of the selected route from MediaControlView2. 248af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * If this is not called, MediaCotrolView2 will not show the route button. 249af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * 250af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * @param routeCategories the list of media control categories in 251af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * {@link android.support.v7.media.MediaControlIntent} 252d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @param player the player to handle playback of the selected route. 253d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * If null, a default route player will be used. 254af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim * @throws IllegalStateException if MediaControlView2 is not set. 255d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @hide 256af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim */ 257af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim public void setRouteAttributes(@NonNull List<String> routeCategories, 2581a2c263c7a60235fc3001d4699f2cac9cd02beb7Jaewan Kim @Nullable MediaPlayerInterface player) { 259af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim mProvider.setRouteAttributes_impl(routeCategories, player); 260af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim } 261af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim 262af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim /** 263d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * Sets a remote player for handling playback of the selected route from MediaControlView2. 264d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * If this is not called, MediaCotrolView2 will not show the route button. 265d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * 266d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @param routeCategories the list of media control categories in 267d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * {@link android.support.v7.media.MediaControlIntent} 268d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @param sessionPlayer the player to handle playback of the selected route. 269d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * If null, a default route player will be used. 270d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @throws IllegalStateException if MediaControlView2 is not set. 271d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim * @hide 272d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim */ 273d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim // TODO: Use MediaPlayerBase once MediaSession2 APIs are ready. 274d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim public void setRouteAttributes(@NonNull List<String> routeCategories, 275d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim @Nullable MediaSession.Callback sessionPlayer) { 276d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim mProvider.setRouteAttributes_impl(routeCategories, sessionPlayer); 277d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim } 278d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim 279d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim /** 280de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Sets video path. 281de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * 282de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * @param path the path of the video. 283e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 284e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public void setVideoPath(String path) { 285e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim mProvider.setVideoPath_impl(path); 286e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 287e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 288e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 289eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Sets video URI. 290eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 291eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param uri the URI of the video. 292e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 293df0728c15af0f6cc101883af097ffe680279448aInsun Kang public void setVideoUri(Uri uri) { 294df0728c15af0f6cc101883af097ffe680279448aInsun Kang mProvider.setVideoUri_impl(uri); 295e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 296e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 297e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 298eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Sets video URI using specific headers. 299eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 300eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param uri the URI of the video. 301eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param headers the headers for the URI request. 302eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Note that the cross domain redirection is allowed by default, but that can be 303eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * changed with key/value pairs through the headers parameter with 304eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value 305eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * to disallow or allow cross domain redirection. 306e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 307df0728c15af0f6cc101883af097ffe680279448aInsun Kang public void setVideoUri(Uri uri, Map<String, String> headers) { 308df0728c15af0f6cc101883af097ffe680279448aInsun Kang mProvider.setVideoUri_impl(uri, headers); 309e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 310e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 311e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 312eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Selects which view will be used to render video between SurfacView and TextureView. 313eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 314eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param viewType the view type to render video 315eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <ul> 316eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li>{@link #VIEW_TYPE_SURFACEVIEW} 317eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li>{@link #VIEW_TYPE_TEXTUREVIEW} 318eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </ul> 319e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 320e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public void setViewType(@ViewType int viewType) { 321e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim mProvider.setViewType_impl(viewType); 322e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 323e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 324e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 325eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Returns view type. 326eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * 327eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @return view type. See {@see setViewType}. 328e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 329e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim @ViewType 330e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public int getViewType() { 331e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim return mProvider.getViewType_impl(); 332e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 333e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 334e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 33546377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * Sets custom actions which will be shown as custom buttons in {@link MediaControlView2}. 33646377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * 33746377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * @param actionList A list of {@link PlaybackState.CustomAction}. The return value of 33846377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * {@link PlaybackState.CustomAction#getIcon()} will be used to draw buttons 33946377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * in {@link MediaControlView2}. 340620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param executor executor to run callbacks on. 34146377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * @param listener A listener to be called when a custom button is clicked. 34246377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon */ 34346377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon public void setCustomActions(List<PlaybackState.CustomAction> actionList, 344620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang Executor executor, OnCustomActionListener listener) { 345620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang mProvider.setCustomActions_impl(actionList, executor, listener); 34646377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon } 34746377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon 34846377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon /** 349eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * Registers a callback to be invoked when a view type change is done. 350eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * {@see #setViewType(int)} 351eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param l The callback that will be run 352a35d1b194696ff73970b640446b2391711ea6030Insun Kang * 353a35d1b194696ff73970b640446b2391711ea6030Insun Kang * @hide 354e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 355a35d1b194696ff73970b640446b2391711ea6030Insun Kang @VisibleForTesting 356a35d1b194696ff73970b640446b2391711ea6030Insun Kang public void setOnViewTypeChangedListener(OnViewTypeChangedListener l) { 357a35d1b194696ff73970b640446b2391711ea6030Insun Kang mProvider.setOnViewTypeChangedListener_impl(l); 358e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 359e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 360e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 361efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon * Registers a callback to be invoked when the fullscreen mode should be changed. 362620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * @param l The callback that will be run 363efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon */ 364a35d1b194696ff73970b640446b2391711ea6030Insun Kang public void setFullScreenRequestListener(OnFullScreenRequestListener l) { 365a35d1b194696ff73970b640446b2391711ea6030Insun Kang mProvider.setFullScreenRequestListener_impl(l); 366efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon } 367efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon 368efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon /** 369df0728c15af0f6cc101883af097ffe680279448aInsun Kang * Interface definition of a callback to be invoked when the view type has been changed. 370a35d1b194696ff73970b640446b2391711ea6030Insun Kang * 371a35d1b194696ff73970b640446b2391711ea6030Insun Kang * @hide 372e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 373a35d1b194696ff73970b640446b2391711ea6030Insun Kang @VisibleForTesting 374e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim public interface OnViewTypeChangedListener { 375e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim /** 376de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang * Called when the view type has been changed. 377eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @see #setViewType(int) 378df0728c15af0f6cc101883af097ffe680279448aInsun Kang * @param view the View whose view type is changed 379eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * @param viewType 380eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <ul> 381eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li>{@link #VIEW_TYPE_SURFACEVIEW} 382eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * <li>{@link #VIEW_TYPE_TEXTUREVIEW} 383eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang * </ul> 384e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim */ 385df0728c15af0f6cc101883af097ffe680279448aInsun Kang void onViewTypeChanged(View view, @ViewType int viewType); 386e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim } 387e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim 388de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang /** 389efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon * Interface definition of a callback to be invoked to inform the fullscreen mode is changed. 390620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang * Application should handle the fullscreen mode accordingly. 391efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon */ 392620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang public interface OnFullScreenRequestListener { 393efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon /** 394efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon * Called to indicate a fullscreen mode change. 395efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon */ 396620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang void onFullScreenRequest(View view, boolean fullScreen); 397efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon } 398efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon 39946377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon /** 40046377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * Interface definition of a callback to be invoked to inform that a custom action is performed. 40146377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon */ 402620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang // TODO: When MediaSession2 is ready, modify the method to match the signature. 40346377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon public interface OnCustomActionListener { 40446377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon /** 40546377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * Called to indicate that a custom action is performed. 40646377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * 40746377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * @param action The action that was originally sent in the 40846377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * {@link PlaybackState.CustomAction}. 40946377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon * @param extras Optional extras. 41046377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon */ 41146377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon void onCustomAction(String action, Bundle extras); 41246377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon } 4138589b7b34bd79d74ad4af218c162f63650161882Insun Kang 4148589b7b34bd79d74ad4af218c162f63650161882Insun Kang @Override 4158589b7b34bd79d74ad4af218c162f63650161882Insun Kang protected void onLayout(boolean changed, int l, int t, int r, int b) { 4168589b7b34bd79d74ad4af218c162f63650161882Insun Kang mProvider.onLayout_impl(changed, l, t, r, b); 4178589b7b34bd79d74ad4af218c162f63650161882Insun Kang } 418e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim} 419