简体   繁体   中英

nullifying MediaPlayer in onCompletion method in Android is not working

I am trying to use onCompletion method to rest, release and nullify the 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". Can somebody please let me know how shall I pass player1 so that I can make it "null".

Thank you very much for the help.

TJ

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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