• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.widget;
18 
19 import android.annotation.NonNull;
20 import android.media.MediaPlayer2;
21 import android.view.View;
22 
23 interface VideoViewInterface {
24     /**
25      * Assigns the view's surface to the given MediaPlayer2 instance.
26      *
27      * @param mp MediaPlayer2
28      * @return true if the surface is successfully assigned, false if not. It will fail to assign
29      *         if any of MediaPlayer2 or surface is unavailable.
30      */
assignSurfaceToMediaPlayer(MediaPlayer2 mp)31     boolean assignSurfaceToMediaPlayer(MediaPlayer2 mp);
setSurfaceListener(SurfaceListener l)32     void setSurfaceListener(SurfaceListener l);
getViewType()33     int getViewType();
setMediaPlayer(MediaPlayer2 mp)34     void setMediaPlayer(MediaPlayer2 mp);
35 
36     /**
37      * Takes over oldView. It means that the MediaPlayer2 will start rendering on this view.
38      * The visibility of oldView will be set as {@link View.GONE}. If the view doesn't have a
39      * MediaPlayer2 instance or its surface is not available, the actual execution is deferred until
40      * a MediaPlayer2 instance is set by {@link #setMediaPlayer} or its surface becomes available.
41      * {@link SurfaceListener.onSurfaceTakeOverDone} will be called when the actual execution is
42      * done.
43      *
44      * @param oldView The view that MediaPlayer2 is currently rendering on.
45      */
takeOver(@onNull VideoViewInterface oldView)46     void takeOver(@NonNull VideoViewInterface oldView);
47 
48     /**
49      * Indicates if the view's surface is available.
50      *
51      * @return true if the surface is available.
52      */
hasAvailableSurface()53     boolean hasAvailableSurface();
54 
55     /**
56      * An instance of VideoViewInterface calls these surface notification methods accordingly if
57      * a listener has been registered via {@link #setSurfaceListener(SurfaceListener)}.
58      */
59     interface SurfaceListener {
onSurfaceCreated(View view, int width, int height)60         void onSurfaceCreated(View view, int width, int height);
onSurfaceDestroyed(View view)61         void onSurfaceDestroyed(View view);
onSurfaceChanged(View view, int width, int height)62         void onSurfaceChanged(View view, int width, int height);
onSurfaceTakeOverDone(VideoViewInterface view)63         void onSurfaceTakeOverDone(VideoViewInterface view);
64     }
65 }
66