implementation 'com.google.android.exoplayer:exoplayer-core:2.X.X'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.X.X'
public class CustomPlayerView extends PlayerView {
private ImageView customPlayButton;
private ProgressBar customProgressBar;
public CustomPlayerView(Context context) {
super(context);
init();
}
public CustomPlayerView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomPlayerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
customPlayButton = findViewById(R.id.customPlayButton);
customProgressBar = findViewById(R.id.customProgressBar);
customPlayButton.setImageResource(R.drawable.custom_play_button);
}
}
<LinearLayout 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"
android:orientation="vertical">
<com.example.myapp.CustomPlayerView
android:id="@+id/customPlayerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:use_controller="true" />
</LinearLayout>
public class MainActivity extends AppCompatActivity {
private CustomPlayerView customPlayerView;
private SimpleExoPlayer exoPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
customPlayerView = findViewById(R.id.customPlayerView);
exoPlayer = ExoPlayerFactory.newSimpleInstance(this);
customPlayerView.setPlayer(exoPlayer);
Uri mediaUri = Uri.parse("https://www.example.com/media.mp4");
MediaSource mediaSource = buildMediaSource(mediaUri);
exoPlayer.prepare(mediaSource);
}
private MediaSource buildMediaSource(Uri uri) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, "exoplayer-codelab");
return new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
}
}