i am trying to implement exoplayer this is my exoplayer
version
implementation 'com.google.android.exoplayer:exoplayer:2.11.1'
i am creating a music player app and i don't know anything about exoplayer
i am trying to implement exoplayer
from last 2 days but it's not working. i couldn't understand anything in the official documentation .
i find many example and tutorial but it's all about playing video using exoplayer
. many example's are using deprecated methods.
I am trying to implement using this tutorial but many of methods are deprecated so it's not working EX.
simpleExoplayer = ExoPlayerFactory.newSimpleInstance(
DefaultRenderersFactory(this),
DefaultTrackSelector(adaptiveTrackSelectionFactory),
DefaultLoadControl()
)
can anyone suggest me where to start or how do i build music streaming app using latest version of exoplayer
.
Any help would be highly appreciated.
Until 2.15.0 version, you can create SimpleExoPlayer instance as the following :
SimpleExoPlayer.Builder(this)
.setMediaSourceFactory(mediaSourceFactory)
.build()
With the 2.16.0 version, SimpleExoPlayer is deprecated, you should use ExoPlayer instance instead. You can create it as the following :
ExoPlayer.Builder(this)
.setMediaSourceFactory(mediaSourceFactory)
.build()
https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/SimpleExoPlayer.Builder.html
For Java Guys (Long Live Java)
In Activity
private PlayerView epPlayerView = findViewById(R.id.design_reference);
The Public Function
public static void runExoPlayer(PlayerView epPlayerView,
String url,
Context context) {
Uri videoUri = Uri.parse(url);
SimpleExoPlayer exoPlayer = new SimpleExoPlayer.Builder(context).build();
epPlayerView.setPlayer(exoPlayer);
MediaItem mediaItem = MediaItem.fromUri(videoUri);
exoPlayer.clearMediaItems();
exoPlayer.setMediaItem(mediaItem);
exoPlayer.prepare();
exoPlayer.setPlayWhenReady(true);
}
Build Gradle
// Exo Media Player
implementation 'com.google.android.exoplayer:exoplayer:2.15.1'
implementation 'com.google.android.exoplayer:exoplayer-core:2.15.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.15.1'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.15.1'
implementation 'com.google.android.exoplayer:exoplayer-hls:2.15.1'
implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.15.1'
androidTestImplementation 'androidx.test:rules:1.4.0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With