/* * 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.media.AudioAttributes; import android.media.AudioManager; import android.media.DataSourceDesc; import android.media.MediaItem2; import android.media.MediaMetadata2; import android.media.MediaPlayer2; import android.media.SessionToken2; import android.media.session.MediaController; import android.media.session.PlaybackState; import android.media.update.ApiLoader; import android.media.update.VideoView2Provider; import android.media.update.ViewGroupHelper; import android.net.Uri; import android.os.Bundle; import android.util.AttributeSet; import android.view.View; import com.android.internal.annotations.VisibleForTesting; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; // TODO: Replace MediaSession wtih MediaSession2 once MediaSession2 is submitted. /** * @hide * Displays a video file. VideoView2 class is a View class which is wrapping {@link MediaPlayer2} * so that developers can easily implement a video rendering application. * *
* Data sources that VideoView2 supports : * VideoView2 can play video files and audio-only files as * well. It can load from various sources such as resources or content providers. The supported * media file formats are the same as {@link MediaPlayer2}. * *
* View type can be selected : * VideoView2 can render videos on top of TextureView as well as * SurfaceView selectively. The default is SurfaceView and it can be changed using * {@link #setViewType(int)} method. Using SurfaceView is recommended in most cases for saving * battery. TextureView might be preferred for supporting various UIs such as animation and * translucency. * *
* Differences between {@link VideoView} class : * VideoView2 covers and inherits the most of * VideoView's functionalities. The main differences are *
* <VideoView2 * android:id="@+id/video_view" * xmlns:widget="http://schemas.android.com/apk/com.android.media.update" * widget:enableControlView="false" /> ** If a developer wants to attach a customed MediaControlView2, then set enableControlView attribute * to false and assign the customed media control widget using {@link #setMediaControlView2}. *
* Audio focus and audio attributes : * By default, VideoView2 requests audio focus with * {@link AudioManager#AUDIOFOCUS_GAIN}. Use {@link #setAudioFocusRequest(int)} to change this * behavior. The default {@link AudioAttributes} used during playback have a usage of * {@link AudioAttributes#USAGE_MEDIA} and a content type of * {@link AudioAttributes#CONTENT_TYPE_MOVIE}, use {@link #setAudioAttributes(AudioAttributes)} to * modify them. * *
* Note: VideoView2 does not retain its full state when going into the background. In particular, it
* does not restore the current play state, play position, selected tracks. Applications should save
* and restore these on their own in {@link android.app.Activity#onSaveInstanceState} and
* {@link android.app.Activity#onRestoreInstanceState}.
*/
public class VideoView2 extends ViewGroupHelperAudioAttributes
.
*/
public void setAudioAttributes(@NonNull AudioAttributes attributes) {
mProvider.setAudioAttributes_impl(attributes);
}
/**
* Sets video path.
*
* @param path the path of the video.
*
* @hide TODO remove
*/
public void setVideoPath(String path) {
mProvider.setVideoPath_impl(path);
}
/**
* Sets video URI.
*
* @param uri the URI of the video.
*
* @hide TODO remove
*/
public void setVideoUri(Uri uri) {
mProvider.setVideoUri_impl(uri);
}
/**
* Sets video URI using specific headers.
*
* @param uri the URI of the video.
* @param headers the headers for the URI request.
* Note that the cross domain redirection is allowed by default, but that can be
* changed with key/value pairs through the headers parameter with
* "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value
* to disallow or allow cross domain redirection.
*
* @hide TODO remove
*/
public void setVideoUri(Uri uri, Map
*
*/
public void setViewType(@ViewType int viewType) {
mProvider.setViewType_impl(viewType);
}
/**
* Returns view type.
*
* @return view type. See {@see setViewType}.
*/
@ViewType
public int getViewType() {
return mProvider.getViewType_impl();
}
/**
* Sets custom actions which will be shown as custom buttons in {@link MediaControlView2}.
*
* @param actionList A list of {@link PlaybackState.CustomAction}. The return value of
* {@link PlaybackState.CustomAction#getIcon()} will be used to draw buttons
* in {@link MediaControlView2}.
* @param executor executor to run callbacks on.
* @param listener A listener to be called when a custom button is clicked.
* @hide TODO remove
*/
public void setCustomActions(List
*
*/
void onViewTypeChanged(View view, @ViewType int viewType);
}
/**
* Interface definition of a callback to be invoked to inform the fullscreen mode is changed.
* Application should handle the fullscreen mode accordingly.
* @hide TODO remove
*/
public interface OnFullScreenRequestListener {
/**
* Called to indicate a fullscreen mode change.
*/
void onFullScreenRequest(View view, boolean fullScreen);
}
/**
* Interface definition of a callback to be invoked to inform that a custom action is performed.
* @hide TODO remove
*/
public interface OnCustomActionListener {
/**
* Called to indicate that a custom action is performed.
*
* @param action The action that was originally sent in the
* {@link PlaybackState.CustomAction}.
* @param extras Optional extras.
*/
void onCustomAction(String action, Bundle extras);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
mProvider.onLayout_impl(changed, l, t, r, b);
}
}