VideoView2.java revision 718c1d122f66ee0b95b8d7cc7f2988730d73461e
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 * &lt;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" /&gt;
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.
155718c1d122f66ee0b95b8d7cc7f2988730d73461eInsun Kang     * @param intervalMs a time interval in milliseconds until VideoView2 hides MediaControlView2.
156e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
157718c1d122f66ee0b95b8d7cc7f2988730d73461eInsun Kang    public void setMediaControlView2(MediaControlView2 mediaControlView, long intervalMs) {
158718c1d122f66ee0b95b8d7cc7f2988730d73461eInsun Kang        mProvider.setMediaControlView2_impl(mediaControlView, intervalMs);
159de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    }
160de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang
161de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    /**
162eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Returns MediaControlView2 instance which is currently attached to VideoView2 by default or by
163eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * {@link #setMediaControlView2} method.
164de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     */
165de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    public MediaControlView2 getMediaControlView2() {
166de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang        return mProvider.getMediaControlView2_impl();
167de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    }
168de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang
169e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
170e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
17182af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim     * Returns MediaController instance which is connected with MediaSession that VideoView2 is
17282af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim     * using. This method should be called when VideoView2 is attached to window, or it throws
17382af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim     * IllegalStateException, since internal MediaSession instance is not available until
17482af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim     * this view is attached to window. Please check {@link android.view.View#isAttachedToWindow}
17582af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim     * before calling this method.
17682af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim     *
17782af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim     * @throws IllegalStateException if interal MediaSession is not created yet.
178e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
17982af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim    public MediaController getMediaController() {
18082af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim        return mProvider.getMediaController_impl();
181e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
182e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
183e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
1844fa8064378770a0e05b7462c173bfb74cb540f37Insun Kang     * Shows or hides closed caption or subtitles if there is any.
185682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang     * The first subtitle track will be chosen if there multiple subtitle tracks exist.
186682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang     * Default behavior of VideoView2 is not showing subtitle.
187682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang     * @param enable shows closed caption or subtitles if this value is true, or hides.
188e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
189682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang    public void setSubtitleEnabled(boolean enable) {
190682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang        mProvider.setSubtitleEnabled_impl(enable);
191682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang    }
192682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang
193682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang    /**
194682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang     * Returns true if showing subtitle feature is enabled or returns false.
195682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang     * Although there is no subtitle track or closed caption, it can return true, if the feature
196682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang     * has been enabled by {@link #setSubtitleEnabled}.
197682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang     */
198682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang    public boolean isSubtitleEnabled() {
199682483d1652bda42e653ea8aa4cbb9f8572c53e7Insun Kang        return mProvider.isSubtitleEnabled_impl();
200e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
201e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
202efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon    /**
203de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * Sets playback speed.
204de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     *
205de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * It is expressed as a multiplicative factor, where normal speed is 1.0f. If it is less than
206de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * or equal to zero, it will be just ignored and nothing will be changed. If it exceeds the
207de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * maximum speed that internal engine supports, system will determine best handling or it will
208de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * be reset to the normal speed 1.0f.
209de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * @param speed the playback speed. It should be positive.
210de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     */
21182af545ca64bff030697a0369e0301c03e8123ecSungsoo Lim    // TODO: Support this via MediaController2.
212de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    public void setSpeed(float speed) {
213de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang        mProvider.setSpeed_impl(speed);
214de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    }
215de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang
216de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    /**
217de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * Sets which type of audio focus will be requested during the playback, or configures playback
218de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * to not request audio focus. Valid values for focus requests are
219de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * {@link AudioManager#AUDIOFOCUS_GAIN}, {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT},
220de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK}, and
221de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}. Or use
222de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * {@link AudioManager#AUDIOFOCUS_NONE} to express that audio focus should not be
223de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * requested when playback starts. You can for instance use this when playing a silent animation
224de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * through this class, and you don't want to affect other audio applications playing in the
225de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * background.
226de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     *
227de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * @param focusGain the type of audio focus gain that will be requested, or
228af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim     *                  {@link AudioManager#AUDIOFOCUS_NONE} to disable the use audio focus during
229af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim     *                  playback.
230e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
231e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    public void setAudioFocusRequest(int focusGain) {
232e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim        mProvider.setAudioFocusRequest_impl(focusGain);
233e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
234e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
235e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
236de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * Sets the {@link AudioAttributes} to be used during the playback of the video.
237de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     *
238de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * @param attributes non-null <code>AudioAttributes</code>.
239e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
240e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    public void setAudioAttributes(@NonNull AudioAttributes attributes) {
241e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim        mProvider.setAudioAttributes_impl(attributes);
242e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
243e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
244e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
245af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim     * Sets a remote player for handling playback of the selected route from MediaControlView2.
246af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim     * If this is not called, MediaCotrolView2 will not show the route button.
247af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim     *
248af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim     * @param routeCategories        the list of media control categories in
249af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim     *                               {@link android.support.v7.media.MediaControlIntent}
250d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     * @param player                 the player to handle playback of the selected route.
251d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     *                               If null, a default route player will be used.
252af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim     * @throws IllegalStateException if MediaControlView2 is not set.
253d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     * @hide
254af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim     */
255af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim    public void setRouteAttributes(@NonNull List<String> routeCategories,
2561a2c263c7a60235fc3001d4699f2cac9cd02beb7Jaewan Kim            @Nullable MediaPlayerInterface player) {
257af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim        mProvider.setRouteAttributes_impl(routeCategories, player);
258af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim    }
259af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim
260af2a1ad069f2fefc162eede7556cd91288a91e8cSungsoo Lim    /**
261d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     * Sets a remote player for handling playback of the selected route from MediaControlView2.
262d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     * If this is not called, MediaCotrolView2 will not show the route button.
263d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     *
264d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     * @param routeCategories        the list of media control categories in
265d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     *                               {@link android.support.v7.media.MediaControlIntent}
266d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     * @param sessionPlayer          the player to handle playback of the selected route.
267d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     *                               If null, a default route player will be used.
268d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     * @throws IllegalStateException if MediaControlView2 is not set.
269d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     * @hide
270d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim     */
271d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim    // TODO: Use MediaPlayerBase once MediaSession2 APIs are ready.
272d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim    public void setRouteAttributes(@NonNull List<String> routeCategories,
273d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim            @Nullable MediaSession.Callback sessionPlayer) {
274d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim        mProvider.setRouteAttributes_impl(routeCategories, sessionPlayer);
275d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim    }
276d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim
277d58f145726a7ef76e4b35dcb528d91549e457e4eSungsoo Lim    /**
278de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * Sets video path.
279de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     *
280de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     * @param path the path of the video.
281e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
282e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    public void setVideoPath(String path) {
283e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim        mProvider.setVideoPath_impl(path);
284e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
285e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
286e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
287eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Sets video URI.
288eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *
289eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @param uri the URI of the video.
290e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
291df0728c15af0f6cc101883af097ffe680279448aInsun Kang    public void setVideoUri(Uri uri) {
292df0728c15af0f6cc101883af097ffe680279448aInsun Kang        mProvider.setVideoUri_impl(uri);
293e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
294e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
295e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
296eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Sets video URI using specific headers.
297eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *
298eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @param uri     the URI of the video.
299eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @param headers the headers for the URI request.
300eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *                Note that the cross domain redirection is allowed by default, but that can be
301eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *                changed with key/value pairs through the headers parameter with
302eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *                "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value
303eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *                to disallow or allow cross domain redirection.
304e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
305df0728c15af0f6cc101883af097ffe680279448aInsun Kang    public void setVideoUri(Uri uri, Map<String, String> headers) {
306df0728c15af0f6cc101883af097ffe680279448aInsun Kang        mProvider.setVideoUri_impl(uri, headers);
307e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
308e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
309e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
310eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Selects which view will be used to render video between SurfacView and TextureView.
311eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *
312eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @param viewType the view type to render video
313eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * <ul>
314eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * <li>{@link #VIEW_TYPE_SURFACEVIEW}
315eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * <li>{@link #VIEW_TYPE_TEXTUREVIEW}
316eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * </ul>
317e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
318e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    public void setViewType(@ViewType int viewType) {
319e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim        mProvider.setViewType_impl(viewType);
320e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
321e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
322e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
323eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Returns view type.
324eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *
325eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @return view type. See {@see setViewType}.
326e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
327e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    @ViewType
328e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    public int getViewType() {
329e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim        return mProvider.getViewType_impl();
330e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
331e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
332e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
33346377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon     * Sets custom actions which will be shown as custom buttons in {@link MediaControlView2}.
33446377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon     *
33546377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon     * @param actionList A list of {@link PlaybackState.CustomAction}. The return value of
33646377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon     *                   {@link PlaybackState.CustomAction#getIcon()} will be used to draw buttons
33746377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon     *                   in {@link MediaControlView2}.
338620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang     * @param executor executor to run callbacks on.
33946377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon     * @param listener A listener to be called when a custom button is clicked.
34046377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon     */
34146377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon    public void setCustomActions(List<PlaybackState.CustomAction> actionList,
342620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang            Executor executor, OnCustomActionListener listener) {
343620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang        mProvider.setCustomActions_impl(actionList, executor, listener);
34446377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon    }
34546377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon
34646377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon    /**
347eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Registers a callback to be invoked when the media file is loaded and ready to go.
348eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *
349620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang     * @param executor executor to run callbacks on.
350eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @param l the callback that will be run.
351e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
352620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang    public void setOnPreparedListener(Executor executor, OnPreparedListener l) {
353620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang        mProvider.setOnPreparedListener_impl(executor, l);
354e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
355e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
356e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
357eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Registers a callback to be invoked when the end of a media file has been reached during
358eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * playback.
359eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *
360620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang     * @param executor executor to run callbacks on.
361eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @param l the callback that will be run.
362e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
363620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang    public void setOnCompletionListener(Executor executor, OnCompletionListener l) {
364620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang        mProvider.setOnCompletionListener_impl(executor, l);
365e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
366e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
367e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
368eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Registers a callback to be invoked when an error occurs during playback or setup.  If no
369eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * listener is specified, or if the listener returned false, VideoView2 will inform the user of
370eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * any errors.
371eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *
372620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang     * @param executor executor to run callbacks on.
373eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @param l The callback that will be run
374e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
375620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang    public void setOnErrorListener(Executor executor, OnErrorListener l) {
376620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang        mProvider.setOnErrorListener_impl(executor, l);
377e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
378e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
379e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
380eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Registers a callback to be invoked when an informational event occurs during playback or
381eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * setup.
382eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     *
383620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang     * @param executor executor to run callbacks on.
384eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @param l The callback that will be run
385e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
386620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang    public void setOnInfoListener(Executor executor, OnInfoListener l) {
387620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang        mProvider.setOnInfoListener_impl(executor, l);
388e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
389e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
390e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
391eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Registers a callback to be invoked when a view type change is done.
392eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * {@see #setViewType(int)}
393620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang     * @param executor executor to run callbacks on.
394eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * @param l The callback that will be run
395e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
396620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang    public void setOnViewTypeChangedListener(Executor executor, OnViewTypeChangedListener l) {
397620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang        mProvider.setOnViewTypeChangedListener_impl(executor, l);
398e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
399e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
400e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    /**
401efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon     * Registers a callback to be invoked when the fullscreen mode should be changed.
402620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang     * @param executor executor to run callbacks on.
403620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang     * @param l The callback that will be run
404efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon     */
405620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang    public void setFullScreenRequestListener(Executor executor, OnFullScreenRequestListener l) {
406620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang        mProvider.setFullScreenRequestListener_impl(executor, l);
407efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon    }
408efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon
409efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon    /**
410df0728c15af0f6cc101883af097ffe680279448aInsun Kang     * Interface definition of a callback to be invoked when the view type has been changed.
411e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim     */
412e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    public interface OnViewTypeChangedListener {
413e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim        /**
414de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         * Called when the view type has been changed.
415eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * @see #setViewType(int)
416df0728c15af0f6cc101883af097ffe680279448aInsun Kang         * @param view the View whose view type is changed
417eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * @param viewType
418eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * <ul>
419eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * <li>{@link #VIEW_TYPE_SURFACEVIEW}
420eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * <li>{@link #VIEW_TYPE_TEXTUREVIEW}
421eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * </ul>
422e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim         */
423df0728c15af0f6cc101883af097ffe680279448aInsun Kang        void onViewTypeChanged(View view, @ViewType int viewType);
424e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim    }
425e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim
426de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    /**
427eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Interface definition of a callback to be invoked when the media source is ready for playback.
428de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     */
429de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    public interface OnPreparedListener {
430de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang        /**
431de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         * Called when the media file is ready for playback.
432de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         */
433df0728c15af0f6cc101883af097ffe680279448aInsun Kang        void onPrepared(View view);
434de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    }
435de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang
436de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    /**
437eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Interface definition for a callback to be invoked when playback of a media source has
438eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * completed.
439de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     */
440de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    public interface OnCompletionListener {
441de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang        /**
442de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         * Called when the end of a media source is reached during playback.
443de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         */
444df0728c15af0f6cc101883af097ffe680279448aInsun Kang        void onCompletion(View view);
445de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    }
446de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang
447de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    /**
448eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Interface definition of a callback to be invoked when there has been an error during an
449eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * asynchronous operation.
450de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     */
451de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    public interface OnErrorListener {
452eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang        // TODO: Redefine error codes.
453de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang        /**
454de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         * Called to indicate an error.
455eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * @param what the type of error that has occurred
456eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * @param extra an extra code, specific to the error.
457eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * @return true if the method handled the error, false if it didn't.
458eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * @see MediaPlayer#OnErrorListener
459de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         */
460df0728c15af0f6cc101883af097ffe680279448aInsun Kang        boolean onError(View view, int what, int extra);
461de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    }
462de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang
463de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    /**
464eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * Interface definition of a callback to be invoked to communicate some info and/or warning
465eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang     * about the media or its playback.
466de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang     */
467de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    public interface OnInfoListener {
468de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang        /**
469de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         * Called to indicate an info or a warning.
470de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         * @param what the type of info or warning.
471de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         * @param extra an extra code, specific to the info.
472eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         *
473eb78d511cb5b06e7c679a090fc13afd74ec15717Insun Kang         * @see MediaPlayer#OnInfoListener
474de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang         */
475df0728c15af0f6cc101883af097ffe680279448aInsun Kang        void onInfo(View view, int what, int extra);
476de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang    }
477de16c4d3579238b49cd3a253e9905196120f9bf0Insun Kang
478efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon    /**
479efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon     * Interface definition of a callback to be invoked to inform the fullscreen mode is changed.
480620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang     * Application should handle the fullscreen mode accordingly.
481efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon     */
482620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang    public interface OnFullScreenRequestListener {
483efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon        /**
484efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon         * Called to indicate a fullscreen mode change.
485efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon         */
486620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang        void onFullScreenRequest(View view, boolean fullScreen);
487efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon    }
488efeb45eabd6b9b2bcb8390e4140c615967c70ddaHyundo Moon
48946377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon    /**
49046377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon     * Interface definition of a callback to be invoked to inform that a custom action is performed.
49146377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon     */
492620b7f328f6e621da4c8fe6695b479bebd147cdbInsun Kang    // TODO: When MediaSession2 is ready, modify the method to match the signature.
49346377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon    public interface OnCustomActionListener {
49446377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon        /**
49546377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon         * Called to indicate that a custom action is performed.
49646377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon         *
49746377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon         * @param action The action that was originally sent in the
49846377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon         *               {@link PlaybackState.CustomAction}.
49946377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon         * @param extras Optional extras.
50046377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon         */
50146377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon        void onCustomAction(String action, Bundle extras);
50246377a9aaea75f5dfc3b9365142c6e65398e2afeHyundo Moon    }
5038589b7b34bd79d74ad4af218c162f63650161882Insun Kang
5048589b7b34bd79d74ad4af218c162f63650161882Insun Kang    @Override
5058589b7b34bd79d74ad4af218c162f63650161882Insun Kang    protected void onLayout(boolean changed, int l, int t, int r, int b) {
5068589b7b34bd79d74ad4af218c162f63650161882Insun Kang        mProvider.onLayout_impl(changed, l, t, r, b);
5078589b7b34bd79d74ad4af218c162f63650161882Insun Kang    }
508e3259049872ea9000b71e8f14d4237a75bc9d606Sungsoo Lim}
509