首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何知道ExoPlayer什么时候准备好玩了?

如何知道ExoPlayer什么时候准备好玩了?
EN

Stack Overflow用户
提问于 2018-04-26 14:42:11
回答 1查看 7K关注 0票数 1

我要用MediaPlayer代替ExoPlayer。我跟着导游https://google.github.io/ExoPlayer/guide.html

代码语言:javascript
复制
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(),因为我不希望它一准备好就开始播放。我在网上读到的唯一方法就是:

代码语言:javascript
复制
        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何时准备播放?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-26 14:57:23

使用Player.DefaultEventListener -这将允许您选择性地覆盖您感兴趣的方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50045884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档