ExoPlayer is an open-source media player for Android that provides an alternative to Androidβs built-in MediaPlayer. It is designed for flexibility, efficiency, and ease of customization, making it a popular choice for apps that require advanced media playback features.
Key Features of ExoPlayer
- Supports Various Formats β ExoPlayer supports MP4, MP3, WebM, MKV, AVI, and streaming formats like DASH, HLS, and SmoothStreaming.
- Adaptive Streaming β Handles different streaming qualities dynamically.
- Customization β Easily customizable and extendable.
- Background Playback β Supports audio and video playback in the background.
- Subtitle and Caption Support β Supports subtitles in multiple formats (e.g., SRT, VTT, TTML).
- Efficient Buffering β Optimized for smooth playback.
- DRM Support β Includes Widevine and PlayReady DRM for protected content.
Liberaries used:
import android.net.Uri;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.ui.PlayerView;
public class MainActivity extends AppCompatActivity {
private ExoPlayer player;
private PlayerView playerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playerView = findViewById(R.id.player_view);
player = new ExoPlayer.Builder(this).build();
playerView.setPlayer(player);
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(“https://www.example.com/sample.mp4”));
player.setMediaItem(mediaItem);
player.prepare();
player.play();
}
@Override
protected void onStop() {
super.onStop();
player.release();
}
}
Reviews
There are no reviews yet.