diff --git a/core/java/android/widget/VideoView2.java b/core/java/android/widget/VideoView2.java new file mode 100644 index 0000000000000..310a7bbdcabf4 --- /dev/null +++ b/core/java/android/widget/VideoView2.java @@ -0,0 +1,363 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.widget; + +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.content.Context; +import android.graphics.Canvas; +import android.media.AudioAttributes; +import android.media.MediaPlayer; +import android.media.update.ApiLoader; +import android.media.update.VideoView2Provider; +import android.media.update.ViewProvider; +import android.net.Uri; +import android.util.AttributeSet; +import android.view.KeyEvent; +import android.view.MotionEvent; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.Map; + +/** + * TODO PUBLIC API + * @hide + */ +public class VideoView2 extends FrameLayout { + @IntDef({ + VIEW_TYPE_TEXTUREVIEW, + VIEW_TYPE_SURFACEVIEW + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ViewType {} + public static final int VIEW_TYPE_SURFACEVIEW = 1; + public static final int VIEW_TYPE_TEXTUREVIEW = 2; + + private final VideoView2Provider mProvider; + + /** + * @hide + */ + public VideoView2(@NonNull Context context) { + this(context, null); + } + + /** + * @hide + */ + public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + /** + * @hide + */ + public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); + } + + /** + * @hide + */ + public VideoView2( + @NonNull Context context, @Nullable AttributeSet attrs, + int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + + mProvider = ApiLoader.getProvider(context).createVideoView2(this, new SuperProvider()); + } + + /** + * @hide + */ + public VideoView2Provider getProvider() { + return mProvider; + } + + /** + * @hide + */ + public void start() { + mProvider.start_impl(); + } + + /** + * @hide + */ + public void pause() { + mProvider.pause_impl(); + } + + /** + * @hide + */ + public int getDuration() { + return mProvider.getDuration_impl(); + } + + /** + * @hide + */ + public int getCurrentPosition() { + return mProvider.getCurrentPosition_impl(); + } + + /** + * @hide + */ + public void seekTo(int msec) { + mProvider.seekTo_impl(msec); + } + + /** + * @hide + */ + public boolean isPlaying() { + return mProvider.isPlaying_impl(); + } + + /** + * @hide + */ + public int getBufferPercentage() { + return mProvider.getBufferPercentage_impl(); + } + + /** + * @hide + */ + public int getAudioSessionId() { + return mProvider.getAudioSessionId_impl(); + } + + /** + * @hide + */ + public void showSubtitle() { + mProvider.showSubtitle_impl(); + } + + /** + * @hide + */ + public void hideSubtitle() { + mProvider.hideSubtitle_impl(); + } + + /** + * @hide + */ + public void setAudioFocusRequest(int focusGain) { + mProvider.setAudioFocusRequest_impl(focusGain); + } + + /** + * @hide + */ + public void setAudioAttributes(@NonNull AudioAttributes attributes) { + mProvider.setAudioAttributes_impl(attributes); + } + + /** + * @hide + */ + public void setVideoPath(String path) { + mProvider.setVideoPath_impl(path); + } + + /** + * @hide + */ + public void setVideoURI(Uri uri) { + mProvider.setVideoURI_impl(uri); + } + + /** + * @hide + */ + public void setVideoURI(Uri uri, Map headers) { + mProvider.setVideoURI_impl(uri, headers); + } + + /** + * @hide + */ + public void setMediaController2(MediaController2 controllerView) { + mProvider.setMediaController2_impl(controllerView); + } + + /** + * @hide + */ + public void setViewType(@ViewType int viewType) { + mProvider.setViewType_impl(viewType); + } + + /** + * @hide + */ + @ViewType + public int getViewType() { + return mProvider.getViewType_impl(); + } + + /** + * @hide + */ + public void stopPlayback() { + mProvider.stopPlayback_impl(); + } + + /** + * @hide + */ + public void setOnPreparedListener(MediaPlayer.OnPreparedListener l) { + mProvider.setOnPreparedListener_impl(l); + } + + /** + * @hide + */ + public void setOnCompletionListener(MediaPlayer.OnCompletionListener l) { + mProvider.setOnCompletionListener_impl(l); + } + + /** + * @hide + */ + public void setOnErrorListener(MediaPlayer.OnErrorListener l) { + mProvider.setOnErrorListener_impl(l); + } + + /** + * @hide + */ + public void setOnInfoListener(MediaPlayer.OnInfoListener l) { + mProvider.setOnInfoListener_impl(l); + } + + /** + * @hide + */ + public void setOnViewTypeChangedListener(OnViewTypeChangedListener l) { + mProvider.setOnViewTypeChangedListener_impl(l); + } + + /** + * @hide + */ + public interface OnViewTypeChangedListener { + /** + * @hide + */ + void onViewTypeChanged(@ViewType int viewType); + } + + @Override + public CharSequence getAccessibilityClassName() { + return mProvider.getAccessibilityClassName_impl(); + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + return mProvider.onTouchEvent_impl(ev); + } + + @Override + public boolean onTrackballEvent(MotionEvent ev) { + return mProvider.onTrackballEvent_impl(ev); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + return mProvider.onKeyDown_impl(keyCode, event); + } + + @Override + public void onFinishInflate() { + mProvider.onFinishInflate_impl(); + } + + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + return mProvider.dispatchKeyEvent_impl(event); + } + + @Override + public void setEnabled(boolean enabled) { + mProvider.setEnabled_impl(enabled); + } + + private class SuperProvider implements ViewProvider { + @Override + public void onAttachedToWindow_impl() { + VideoView2.super.onAttachedToWindow(); + } + + @Override + public void onDetachedFromWindow_impl() { + VideoView2.super.onDetachedFromWindow(); + } + + @Override + public void onLayout_impl(boolean changed, int left, int top, int right, int bottom) { + VideoView2.super.onLayout(changed, left, top, right, bottom); + } + + @Override + public void draw_impl(Canvas canvas) { + VideoView2.super.draw(canvas); + } + + @Override + public CharSequence getAccessibilityClassName_impl() { + return VideoView2.super.getAccessibilityClassName(); + } + + @Override + public boolean onTouchEvent_impl(MotionEvent ev) { + return VideoView2.super.onTouchEvent(ev); + } + + @Override + public boolean onTrackballEvent_impl(MotionEvent ev) { + return VideoView2.super.onTrackballEvent(ev); + } + + @Override + public boolean onKeyDown_impl(int keyCode, KeyEvent event) { + return VideoView2.super.onKeyDown(keyCode, event); + } + + @Override + public void onFinishInflate_impl() { + VideoView2.super.onFinishInflate(); + } + + @Override + public boolean dispatchKeyEvent_impl(KeyEvent event) { + return VideoView2.super.dispatchKeyEvent(event); + } + + @Override + public void setEnabled_impl(boolean enabled) { + VideoView2.super.setEnabled(enabled); + } + } +} diff --git a/media/java/android/media/update/StaticProvider.java b/media/java/android/media/update/StaticProvider.java index 19f01c2bcc7fb..a1e2404ca78ae 100644 --- a/media/java/android/media/update/StaticProvider.java +++ b/media/java/android/media/update/StaticProvider.java @@ -18,6 +18,7 @@ package android.media.update; import android.annotation.SystemApi; import android.widget.MediaController2; +import android.widget.VideoView2; /** * Interface for connecting the public API to an updatable implementation. @@ -31,4 +32,5 @@ import android.widget.MediaController2; public interface StaticProvider { MediaController2Provider createMediaController2( MediaController2 instance, ViewProvider superProvider); + VideoView2Provider createVideoView2(VideoView2 instance, ViewProvider superProvider); } diff --git a/media/java/android/media/update/VideoView2Provider.java b/media/java/android/media/update/VideoView2Provider.java new file mode 100644 index 0000000000000..6fc9bdc64e027 --- /dev/null +++ b/media/java/android/media/update/VideoView2Provider.java @@ -0,0 +1,66 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media.update; + +import android.media.AudioAttributes; +import android.media.MediaPlayer; +import android.net.Uri; +import android.widget.MediaController2; +import android.widget.VideoView2; + +import java.util.Map; + +/** + * Interface for connecting the public API to an updatable implementation. + * + * Each instance object is connected to one corresponding updatable object which implements the + * runtime behavior of that class. There should a corresponding provider method for all public + * methods. + * + * All methods behave as per their namesake in the public API. + * + * @see android.widget.VideoView2 + * + * @hide + */ +// TODO @SystemApi +public interface VideoView2Provider extends ViewProvider { + void start_impl(); + void pause_impl(); + int getDuration_impl(); + int getCurrentPosition_impl(); + void seekTo_impl(int msec); + boolean isPlaying_impl(); + int getBufferPercentage_impl(); + int getAudioSessionId_impl(); + void showSubtitle_impl(); + void hideSubtitle_impl(); + void setAudioFocusRequest_impl(int focusGain); + void setAudioAttributes_impl(AudioAttributes attributes); + void setVideoPath_impl(String path); + void setVideoURI_impl(Uri uri); + void setVideoURI_impl(Uri uri, Map headers); + void setMediaController2_impl(MediaController2 controllerView); + void setViewType_impl(int viewType); + int getViewType_impl(); + void stopPlayback_impl(); + void setOnPreparedListener_impl(MediaPlayer.OnPreparedListener l); + void setOnCompletionListener_impl(MediaPlayer.OnCompletionListener l); + void setOnErrorListener_impl(MediaPlayer.OnErrorListener l); + void setOnInfoListener_impl(MediaPlayer.OnInfoListener l); + void setOnViewTypeChangedListener_impl(VideoView2.OnViewTypeChangedListener l); +}