Я заменяю MediaPlayer на ExoPlayer.
Я следовал за гидом
https://google.github.io/ExoPlayer/guide.html
public class cl_ExoPlayer {
Map<String,SimpleExoPlayer> player = new HashMap<String,SimpleExoPlayer>();
Integer are_loading = 0 ;
// 1. Create a default TrackSelector
Handler mainHandler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory audioTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(audioTrackSelectionFactory);
void snd_load( String file_name , String url ) {
try {
String file_name_with_ext = url.substring(url.lastIndexOf("/") + 1); // snd_title.ogg
String file_name_without_ext = file_name_with_ext.substring(0, file_name_with_ext.indexOf(".")); // snd_title
Uri uri ;
int resId = getApplicationContext().getResources().getIdentifier(file_name_without_ext, "raw", getApplicationContext().getPackageName());
if (resId != 0){ uri = Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/raw/" + file_name_without_ext); }
else{ uri = Uri.parse("http://diegotests.altervista.org/html5_games/8bit_pocket_wrestlers/" + url); }
// 2. Create the player
player.put( file_name, ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector) );
// Measures bandwidth during playback. Can be null if not required.
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),
Util.getUserAgent(getApplicationContext(), "yourApplicationName"), bandwidthMeter);
// This is the MediaSource representing the media to be played.
MediaSource audioSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri);
// Prepare the player with the source.
are_loading++;
player.get(file_name).prepare(audioSource);
Теперь я хочу знать, когда он завершит загрузку файла, расшифровку и готов к воспроизведению. Я не использую .setPlayWhenReady (), потому что я НЕ хочу, чтобы он начал играть, как только он будет готов. Единственный способ, которым я читаю в Интернете, это всегда:
player.get(file_name).addListener( new Player.EventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == Player.STATE_READY) {
}
}
});
Но это не работает.
Я получаю ошибку
error: <anonymous didi.a8bitpocketwrestlers.cl_ExoPlayer$1> is not abstract and does not override abstract method onSeekProcessed() in EventListener
Я прочитал много страниц об этой ошибке, но до сих пор не понимаю, каждый раз она так сильно отличается от того, что я пытаюсь сделать здесь.
Если я не могу добавить прослушиватель событий, есть ли другой способ узнать, когда ExoPlayer готов к воспроизведению?