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