FullscreenVideoView — VideoView gone fullscreen

Slavi Petrov
Dev Labs
Published in
3 min readNov 14, 2017

--

I was once given the task to create a VideoView with fullscreen functionality. It was a great challenge because the default VideoView doesn’t have this included by default. I searched all over the Internet and didn’t find an appropriate solution for this.

So I’ve decided to make a library called FullscreenVideoView. It does the same as the first part of its name loudly presents — goes fullscreen on orientation change (if enabled by the user) or by clicking on the fullscreen button. It’s a combination of several classes, that handle the orientation change, a video controller, a media player, and the actual FullscreenVideoView class.

How to set up the library?

  1. Add FullscreenVideoView to your layout’s XML file:

2. Set the video file or its URL:

3. The Activity should handle configuration changes and you need to add the configChanges attribute to the AndroidManifest:

You’re probably thinking “Is that all?”

Yes, that is all you have to do to get the library to work.

Advanced usage

You can enable video auto-start which is disabled by default:

Customize drawables, by using drawable resource ids:

or drawable objects:

Change the fast rewind/fast forward intervals:

Change the progress bar color by passing a color resource id:

How orientation change can be handled?

To avoid passing the wrong orientation for portrait or landscape, I created PortraitOrientation and LandscapeOrientation enums. They wrap the portrait and landscape orientation constants from ActivityInfo which are described here.

Enable/disable the pause, fast-forward or rewind:

Change the playback speed (only for API 23 and above)

The speed of the video can be changed with the library methods below. There are 7 playback speed values which are added by default, but they can be changed with custom ones when playbackSpeedOptions is used.

Add thumbnail

You can add a thumbnail to the video by calling the thumbnail method. It supports only project drawable files.

Play/Pause the video programmatically

There is support for playing/pausing the videos programmatically by just calling the play/pause method.

Hide the progress views

The library offers an option for hiding the progress views (current time TextView, end time TextView and the ProgressBar) by calling the hideProgress method.

Hide the fullscreen button

There is an option to hide the fullscreen button. Just call the hideFullscreenButton method it will be gone.

Listen for errors

You can listen for errors by adding onErrorListener to the FullscreenVideoView initially from the Builder or later by calling the view method.

Listen for Media Controller events

To listen for Media Controller events you should use the Builder function mediaControllerListener. You can either pass the MediaControllerListener interface or MediaControllerListenerAdapter abstract class if don't need to use all of the methods of the interface.

What about XML properties?

The VideoView can also be styled from XML:

Download

You can use Gradle:

or Maven:

This is what the library covers so far. If you find any bugs or you have an idea about a feature submit an issue on GitHub. Pull requests are welcome. Check it out on GitHub.

--

--