See how to begin creating your new ExoPlayer app. Learn how to create your video and audio ExoPlayer classes.
- [Instructor] In this video, we will take some of the ideas we've learned when writing the media player app, and apply them to an app that uses the ExoPlayer library. Let's start by opening up the starter project that has a UI already defined. This will be similar to our media player app. Open up activity_main, and you'll see two buttons at the bottom for playing and pausing audio, and a new control called player view from the ExoPlayer library. This widget is used for playing video. We set the widget to take the full screen, and use a special attribute called resize-mode and set it to fit. Open up MainActivity, and let's add some new variables. One for the audio player and one for the video player. We'll call it videoExoPlayer, and it would be a simple player. Let's go ahead and copy that, and we'll make an audioExoPlayer. Alright, now that they are both SimpleExoPlayer instances, we will set up and use one for audio and the other for video. The SimpleExoPlayer can both play video and audio, let's start by creating methods to create our players. Create two methods, create video player and create audio player. First, we'll create the video player, we'll need to create some variables, one called the trackSelector, and we'll use a DefaultTrackSelector. Next, we'll create a loadControl, and we'll use the DefaultLoadControl. Next, we'll create a renderersFactory, and we'll use the DefaultRenderersFactory. And we'll pass this in as the context, and then we'll create our videoExoPlayer, and we'll use the ExoPlayerFcatory, and we'll say newSimpleInstance, and we'll pass in this as a context, the renderersFactory, the trackSelector and then the loadControl. Since this is a video player, we want to set the scaling. We'd set the video player, VideoScalingMode, to be, we'll use a C class that comes with the Exo player, and we'll set it to VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING. That will crop and fit the video to fit the screen. Next, let's create the audio player. We'll use some of the same variables as the other ones, we'll copy those. And we'll use the audioExoPlayer to create it. We talked about the trackSelector in the loadControl classes in an earlier video. These methods do the same things, except that the video player sets the scaling mode. This is one important distinction between the video view widget and ExoPlayer library. The player view classes can keep the aspect ratio of the video.
- Why your app needs audio and video
- Controlling volume with AudioManager
- Playing audio with MediaPlayer
- Playing multiple sound files at once with SoundPool
- Creating a VideoView UI
- Playing media in the background
- Audio and video formats
- Working with ExoPlayer