Merge "Initial commit for VideoView2Impl"
This commit is contained in:
committed by
Android (Google) Code Review
commit
24de6a45aa
@@ -19,129 +19,144 @@ package android.widget;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.media.session.MediaController;
|
||||
import android.media.update.ApiLoader;
|
||||
import android.media.update.MediaController2Provider;
|
||||
import android.media.update.MediaControlView2Provider;
|
||||
import android.media.update.ViewProvider;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
||||
/**
|
||||
* TODO PUBLIC API
|
||||
* @hide
|
||||
*/
|
||||
public class MediaController2 extends FrameLayout {
|
||||
private final MediaController2Provider mProvider;
|
||||
public class MediaControlView2 extends FrameLayout {
|
||||
private final MediaControlView2Provider mProvider;
|
||||
|
||||
public MediaController2(@NonNull Context context) {
|
||||
public MediaControlView2(@NonNull Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public MediaController2(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
public MediaControlView2(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public MediaController2(@NonNull Context context, @Nullable AttributeSet attrs,
|
||||
public MediaControlView2(@NonNull Context context, @Nullable AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
this(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
public MediaController2(@NonNull Context context, @Nullable AttributeSet attrs,
|
||||
public MediaControlView2(@NonNull Context context, @Nullable AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
|
||||
mProvider = ApiLoader.getProvider(context)
|
||||
.createMediaController2(this, new SuperProvider());
|
||||
.createMediaControlView2(this, new SuperProvider());
|
||||
}
|
||||
|
||||
public MediaControlView2Provider getProvider() {
|
||||
return mProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public void setController(MediaController controller) {
|
||||
mProvider.setController_impl(controller);
|
||||
}
|
||||
|
||||
public void setAnchorView(View view) {
|
||||
mProvider.setAnchorView_impl(view);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public void show() {
|
||||
mProvider.show_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public void show(int timeout) {
|
||||
mProvider.show_impl(timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public boolean isShowing() {
|
||||
return mProvider.isShowing_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public void hide() {
|
||||
mProvider.hide_impl();
|
||||
}
|
||||
|
||||
public void setPrevNextListeners(OnClickListener next, OnClickListener prev) {
|
||||
mProvider.setPrevNextListeners_impl(next, prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public void showCCButton() {
|
||||
mProvider.showCCButton_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public boolean isPlaying() {
|
||||
return mProvider.isPlaying_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public int getCurrentPosition() {
|
||||
return mProvider.getCurrentPosition_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public int getBufferPercentage() {
|
||||
return mProvider.getBufferPercentage_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public boolean canPause() {
|
||||
return mProvider.canPause_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public boolean canSeekBackward() {
|
||||
return mProvider.canSeekBackward_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public boolean canSeekForward() {
|
||||
return mProvider.canSeekForward_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public void showSubtitle() {
|
||||
mProvider.showSubtitle_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: add docs
|
||||
*/
|
||||
public void hideSubtitle() {
|
||||
mProvider.hideSubtitle_impl();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
mProvider.onAttachedToWindow_impl();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
mProvider.onDetachedFromWindow_impl();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
mProvider.onLayout_impl(changed, left, top, right, bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
mProvider.draw_impl(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getAccessibilityClassName() {
|
||||
return mProvider.getAccessibilityClassName_impl();
|
||||
@@ -178,59 +193,39 @@ public class MediaController2 extends FrameLayout {
|
||||
}
|
||||
|
||||
private class SuperProvider implements ViewProvider {
|
||||
@Override
|
||||
public void onAttachedToWindow_impl() {
|
||||
MediaController2.super.onAttachedToWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow_impl() {
|
||||
MediaController2.super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayout_impl(boolean changed, int left, int top, int right, int bottom) {
|
||||
MediaController2.super.onLayout(changed, left, top, right, bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw_impl(Canvas canvas) {
|
||||
MediaController2.super.draw(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getAccessibilityClassName_impl() {
|
||||
return MediaController2.super.getAccessibilityClassName();
|
||||
return MediaControlView2.super.getAccessibilityClassName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent_impl(MotionEvent ev) {
|
||||
return MediaController2.super.onTouchEvent(ev);
|
||||
return MediaControlView2.super.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTrackballEvent_impl(MotionEvent ev) {
|
||||
return MediaController2.super.onTrackballEvent(ev);
|
||||
return MediaControlView2.super.onTrackballEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown_impl(int keyCode, KeyEvent event) {
|
||||
return MediaController2.super.onKeyDown(keyCode, event);
|
||||
return MediaControlView2.super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishInflate_impl() {
|
||||
MediaController2.super.onFinishInflate();
|
||||
MediaControlView2.super.onFinishInflate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent_impl(KeyEvent event) {
|
||||
return MediaController2.super.dispatchKeyEvent(event);
|
||||
return MediaControlView2.super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled_impl(boolean enabled) {
|
||||
MediaController2.super.setEnabled(enabled);
|
||||
MediaControlView2.super.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,8 @@ 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.AudioManager;
|
||||
import android.media.update.ApiLoader;
|
||||
import android.media.update.VideoView2Provider;
|
||||
import android.media.update.ViewProvider;
|
||||
@@ -80,7 +79,8 @@ public class VideoView2 extends FrameLayout {
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
|
||||
mProvider = ApiLoader.getProvider(context).createVideoView2(this, new SuperProvider());
|
||||
mProvider = ApiLoader.getProvider(context).createVideoView2(this, new SuperProvider(),
|
||||
attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,6 +90,20 @@ public class VideoView2 extends FrameLayout {
|
||||
return mProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public void setMediaControlView2(MediaControlView2 mediaControlView) {
|
||||
mProvider.setMediaControlView2_impl(mediaControlView);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public MediaControlView2 getMediaControlView2() {
|
||||
return mProvider.getMediaControlView2_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@@ -161,6 +175,45 @@ public class VideoView2 extends FrameLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets playback speed.
|
||||
*
|
||||
* It is expressed as a multiplicative factor, where normal speed is 1.0f. If it is less than
|
||||
* or equal to zero, it will be just ignored and nothing will be changed. If it exceeds the
|
||||
* maximum speed that internal engine supports, system will determine best handling or it will
|
||||
* be reset to the normal speed 1.0f.
|
||||
* TODO: This should be revised after integration with MediaPlayer2.
|
||||
* @param speed the playback speed. It should be positive.
|
||||
* @hide
|
||||
*/
|
||||
public void setSpeed(float speed) {
|
||||
mProvider.setSpeed_impl(speed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current speed setting.
|
||||
*
|
||||
* If setSpeed() has never been called, returns the default value 1.0f.
|
||||
* @return current speed setting
|
||||
* @hide
|
||||
*/
|
||||
public float getSpeed() {
|
||||
return mProvider.getSpeed_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets which type of audio focus will be requested during the playback, or configures playback
|
||||
* to not request audio focus. Valid values for focus requests are
|
||||
* {@link AudioManager#AUDIOFOCUS_GAIN}, {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT},
|
||||
* {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK}, and
|
||||
* {@link AudioManager#AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE}. Or use
|
||||
* {@link AudioManager#AUDIOFOCUS_NONE} to express that audio focus should not be
|
||||
* requested when playback starts. You can for instance use this when playing a silent animation
|
||||
* through this class, and you don't want to affect other audio applications playing in the
|
||||
* background.
|
||||
*
|
||||
* @param focusGain the type of audio focus gain that will be requested, or
|
||||
* {@link AudioManager#AUDIOFOCUS_NONE} to disable the use audio focus during playback.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void setAudioFocusRequest(int focusGain) {
|
||||
@@ -168,6 +221,10 @@ public class VideoView2 extends FrameLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link AudioAttributes} to be used during the playback of the video.
|
||||
*
|
||||
* @param attributes non-null <code>AudioAttributes</code>.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void setAudioAttributes(@NonNull AudioAttributes attributes) {
|
||||
@@ -175,6 +232,9 @@ public class VideoView2 extends FrameLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets video path.
|
||||
*
|
||||
* @param path the path of the video.
|
||||
* @hide
|
||||
*/
|
||||
public void setVideoPath(String path) {
|
||||
@@ -195,13 +255,6 @@ public class VideoView2 extends FrameLayout {
|
||||
mProvider.setVideoURI_impl(uri, headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public void setMediaController2(MediaController2 controllerView) {
|
||||
mProvider.setMediaController2_impl(controllerView);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@@ -227,28 +280,28 @@ public class VideoView2 extends FrameLayout {
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public void setOnPreparedListener(MediaPlayer.OnPreparedListener l) {
|
||||
public void setOnPreparedListener(OnPreparedListener l) {
|
||||
mProvider.setOnPreparedListener_impl(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public void setOnCompletionListener(MediaPlayer.OnCompletionListener l) {
|
||||
public void setOnCompletionListener(OnCompletionListener l) {
|
||||
mProvider.setOnCompletionListener_impl(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public void setOnErrorListener(MediaPlayer.OnErrorListener l) {
|
||||
public void setOnErrorListener(OnErrorListener l) {
|
||||
mProvider.setOnErrorListener_impl(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public void setOnInfoListener(MediaPlayer.OnInfoListener l) {
|
||||
public void setOnInfoListener(OnInfoListener l) {
|
||||
mProvider.setOnInfoListener_impl(l);
|
||||
}
|
||||
|
||||
@@ -260,15 +313,61 @@ public class VideoView2 extends FrameLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition of a callback to be invoked when the viw type has been changed.
|
||||
* @hide
|
||||
*/
|
||||
public interface OnViewTypeChangedListener {
|
||||
/**
|
||||
* @hide
|
||||
* Called when the view type has been changed.
|
||||
* @see VideoView2#setViewType(int)
|
||||
*/
|
||||
void onViewTypeChanged(@ViewType int viewType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public interface OnPreparedListener {
|
||||
/**
|
||||
* Called when the media file is ready for playback.
|
||||
*/
|
||||
void onPrepared();
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public interface OnCompletionListener {
|
||||
/**
|
||||
* Called when the end of a media source is reached during playback.
|
||||
*/
|
||||
void onCompletion();
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public interface OnErrorListener {
|
||||
/**
|
||||
* Called to indicate an error.
|
||||
*/
|
||||
boolean onError(int what, int extra);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public interface OnInfoListener {
|
||||
/**
|
||||
* Called to indicate an info or a warning.
|
||||
* @see MediaPlayer#OnInfoListener
|
||||
*
|
||||
* @param what the type of info or warning.
|
||||
* @param extra an extra code, specific to the info.
|
||||
*/
|
||||
void onInfo(int what, int extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getAccessibilityClassName() {
|
||||
return mProvider.getAccessibilityClassName_impl();
|
||||
@@ -305,26 +404,6 @@ public class VideoView2 extends FrameLayout {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* Copyright 2017 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.
|
||||
@@ -19,7 +19,6 @@ package android.media.update;
|
||||
import android.annotation.SystemApi;
|
||||
import android.media.session.MediaController;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
||||
/**
|
||||
* Interface for connecting the public API to an updatable implementation.
|
||||
@@ -30,19 +29,17 @@ import android.view.View.OnClickListener;
|
||||
*
|
||||
* All methods behave as per their namesake in the public API.
|
||||
*
|
||||
* @see android.widget.MediaController2
|
||||
* @see android.widget.MediaControlView2
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
// TODO @SystemApi
|
||||
public interface MediaController2Provider extends ViewProvider {
|
||||
public interface MediaControlView2Provider extends ViewProvider {
|
||||
void setController_impl(MediaController controller);
|
||||
void setAnchorView_impl(View view);
|
||||
void show_impl();
|
||||
void show_impl(int timeout);
|
||||
boolean isShowing_impl();
|
||||
void hide_impl();
|
||||
void setPrevNextListeners_impl(OnClickListener next, OnClickListener prev);
|
||||
void showCCButton_impl();
|
||||
boolean isPlaying_impl();
|
||||
int getCurrentPosition_impl();
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
package android.media.update;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SystemApi;
|
||||
import android.widget.MediaController2;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.MediaControlView2;
|
||||
import android.widget.VideoView2;
|
||||
|
||||
/**
|
||||
@@ -30,7 +32,9 @@ import android.widget.VideoView2;
|
||||
*/
|
||||
// TODO @SystemApi
|
||||
public interface StaticProvider {
|
||||
MediaController2Provider createMediaController2(
|
||||
MediaController2 instance, ViewProvider superProvider);
|
||||
VideoView2Provider createVideoView2(VideoView2 instance, ViewProvider superProvider);
|
||||
MediaControlView2Provider createMediaControlView2(
|
||||
MediaControlView2 instance, ViewProvider superProvider);
|
||||
VideoView2Provider createVideoView2(
|
||||
VideoView2 instance, ViewProvider superProvider,
|
||||
@Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes);
|
||||
}
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
package android.media.update;
|
||||
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.widget.MediaController2;
|
||||
import android.widget.MediaControlView2;
|
||||
import android.widget.VideoView2;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -39,6 +38,8 @@ import java.util.Map;
|
||||
*/
|
||||
// TODO @SystemApi
|
||||
public interface VideoView2Provider extends ViewProvider {
|
||||
void setMediaControlView2_impl(MediaControlView2 mediaControlView);
|
||||
MediaControlView2 getMediaControlView2_impl();
|
||||
void start_impl();
|
||||
void pause_impl();
|
||||
int getDuration_impl();
|
||||
@@ -49,18 +50,19 @@ public interface VideoView2Provider extends ViewProvider {
|
||||
int getAudioSessionId_impl();
|
||||
void showSubtitle_impl();
|
||||
void hideSubtitle_impl();
|
||||
void setSpeed_impl(float speed);
|
||||
float getSpeed_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<String, String> 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 setOnPreparedListener_impl(VideoView2.OnPreparedListener l);
|
||||
void setOnCompletionListener_impl(VideoView2.OnCompletionListener l);
|
||||
void setOnErrorListener_impl(VideoView2.OnErrorListener l);
|
||||
void setOnInfoListener_impl(VideoView2.OnInfoListener l);
|
||||
void setOnViewTypeChangedListener_impl(VideoView2.OnViewTypeChangedListener l);
|
||||
}
|
||||
|
||||
@@ -37,10 +37,6 @@ import android.view.MotionEvent;
|
||||
// TODO @SystemApi
|
||||
public interface ViewProvider {
|
||||
// TODO Add more (all?) methods from View
|
||||
void onAttachedToWindow_impl();
|
||||
void onDetachedFromWindow_impl();
|
||||
void onLayout_impl(boolean changed, int left, int top, int right, int bottom);
|
||||
void draw_impl(Canvas canvas);
|
||||
CharSequence getAccessibilityClassName_impl();
|
||||
boolean onTouchEvent_impl(MotionEvent ev);
|
||||
boolean onTrackballEvent_impl(MotionEvent ev);
|
||||
|
||||
Reference in New Issue
Block a user