VideoView

public class VideoView
extends ViewGroup

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ androidx.media2.widget.VideoView


A high level view for media playback that can be integrated with either a SessionPlayer or a MediaController. Developers can easily implement a video rendering application using this class. By default, a MediaControlView is attached so the playback control buttons are displayed on top of VideoView.

Contents:

  1. Using VideoView with SessionPlayer or MediaController
  2. Using VideoView with MediaControlView
  3. Choosing a view type
  4. Comparison with android.widget.VideoView
  5. Displaying Metadata

Using VideoView with SessionPlayer or MediaController

Using VideoView with MediaControlView

VideoView is working with MediaControlView and a MediaControlView instance is attached to VideoView by default.

If you want to attach a custom MediaControlView, assign the custom media control widget using setMediaControlView(MediaControlView, long).

If you don't want to use MediaControlView, set the VideoView attribute R.attr.enableControlView to false.

Choosing a view type

VideoView can render videos on a TextureView or SurfaceView. The default is SurfaceView which can be changed by using the setViewType(int) method or by setting the R.attr.viewType attribute in the layout file.

SurfaceView is recommended in most cases for saving battery life. TextureView might be preferred for supporting various UIs such as animation and translucency.

Comparison with android.widget.VideoView

These are the main differences between the media2 VideoView widget and the older android widget: