简体   繁体   English

使Android中的onCompletion方法中的MediaPlayer无效

[英]nullifying MediaPlayer in onCompletion method in Android is not working

I am trying to use onCompletion method to rest, release and nullify the MediaPlayer. 我正在尝试使用onCompletion方法来休息,释放和使MediaPlayer无效。 I am doing this as follows: 我这样做如下:

    @Override
    public void onClick(View v) {

        if (player1 == null) {
            player1 = new MediaPlayer();
            player1.setVolume(10, 10);
            player1.setOnCompletionListener(this);
        }


        switch (v.getId()) {
               .
               . 
               .

    public void onCompletion(MediaPlayer player1) {
        player1.reset();
        player1.release();
        player1 = null;
                .
                .
                .

However, when I try to debug in Eclips, I see that player1 is not "null". 但是,当我尝试在Eclips中调试时,我看到player1不是“ null”。 Can somebody please let me know how shall I pass player1 so that I can make it "null". 有人可以让我知道如何通过player1以便使它成为“ null”。

Thank you very much for the help. 非常感谢你的帮助。

TJ TJ

尝试使用this.player1=null因为在onCompletion事件中您将null设置为局部变量,而在onClick事件中您正在检查成员变量,当前在上面的代码中不可见,但我猜测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM