方法无法在Android上启动?

时间:2021-12-29 01:32:11

My custom audio application starts to play when the Main activity begins, but I'd like it to start playing when the user hits the "Play" button. Just for the record I'm not using the Android MediaPlayer, but my own player.

我的自定义音频应用程序在Main活动开始时开始播放,但我希望它在用户点击“播放”按钮时开始播放。仅仅是为了记录,我没有使用Android MediaPlayer,而是我自己的播放器。

When I simply use startPlayer() it runs fine, when the Activity starts, but when I put the startPlayer() invokation inside the setOnClickListener() it doesn't work.

当我简单地使用startPlayer()时,它运行良好,当Activity启动时,但是当我将startPlayer()invokation放在setOnClickListener()中时它不起作用。

The method startPlayer() in being called (it's logging fine), but the audio player doesn't fire up. Why?

调用方法startPlayer()(它的记录正常),但音频播放器不会启动。为什么?

Here is the code:

这是代码:

play = (Button) findViewById(R.id.playbutton);
        play.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {                               
                startPlayer();

            }
        });


    }

    private void startPlayer() {
        try {
            player.playAudio();     

        } catch (Exception e) {
            e.printStackTrace();
            finish();
        }
    }

1 个解决方案

#1


0  

    play.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {                               
            startPlayer();
        }
    });

#1


0  

    play.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {                               
            startPlayer();
        }
    });