In most cases the Android VideoView doesn't handle full HD playback or HTTP Live Streaming (HLS) correctly; stopping mid playback, dropping many frames, or just not playing at all. The ExoPlayer was built by Google as the solution for YouTube (tm) and the Google Play (tm) apps, however using the ExoPlayer takes a lot of setup most developers don't want to deal with. That's where ExoMedia comes in to play, it simplifies the API interface to match those of the standard Android VideoView, allowing for a quick replacement.
Additionally, an AudioPlayer has been built around the ExoPlayer, again using an API interface to match the standard Android MediaPlayer.
compile 'com.devbrackets.android:exomedia:4.0.0'
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.devbrackets.android.exomedia.ui.widget.VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:useDefaultControls="true"/>
</RelativeLayout>
private void setupVideoView() {
// Note: Make sure to import the correct VideoView
VideoView videoView = (VideoView)findViewById(R.id.video_view);
videoView.setOnPreparedListener(this);
//For now we just picked an arbitrary item to play. More can be found at
//https://archive.org/details/more_animation
emVideoView.setVideoURI(Uri.parse("https://archive.org/download/Popeye_forPresident/Popeye_forPresident_512kb.mp4"));
}
@Override
public void onPrepared() {
//Starts the video playback as soon as it is ready
videoView.start();
}
Copyright 2015-2017 Brian Wernick 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.