永远不会调用MediaPlayer onError

时间:2019-01-04 11:28:18

标签: java interface android-mediaplayer

从未调用MediaPlayer onError,即使在start ()之后,我也试图进行设置,但差异没有改变,也许问题出在异步调用中……但是有没有禁用prepareAsync ()的解决方案吗?

public void play() {
    try {
        if(player != null){
            player.stop();
            player.release();
            player = null;
        }

        player = new MediaPlayer();
        player.setLooping(false);
        surfaceHolder.addCallback(new SurfaceHolder.Callback() {
            @Override
            public void surfaceCreated(SurfaceHolder surfaceHolder) {
                player.setDisplay(surfaceHolder);
            }

            @Override
            public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {}

            @Override
            public void surfaceDestroyed(SurfaceHolder surfaceHolder) {}
        });

        playerView.setVisibility(View.INVISIBLE);
        player.setDataSource(urls[current]);
        player.prepareAsync();
        player.setOnErrorListener((mediaPlayer, error, i1) -> {
            Log.e("ErrorListener", "error=" + error);
            return false;
        });
        player.setOnPreparedListener(mediaPlayer -> {
            player.start();
            playerView.setVisibility(View.VISIBLE);
        });

    } catch (Exception ex){
        menu.progressDialog.dismiss();
        Log.e("ErrorException", "" + ex.toString());
    }
}

Void play ()在此类中。其中“ VideoPlayer”是“接口”:

public class myMediaPlayer implements VideoPlayer {
}

错误肯定存在。但不会发生呼叫,除非未调用“ OnPrepared”。

0 个答案:

没有答案