3的MediaController第2期 [英] MediaController 3 Second Issue

查看:173
本文介绍了3的MediaController第2期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用的MediaController并改变它,这样它不会在3秒后消失。我发现这code在一个相关的问题,我用它:

I am trying to use a MediaController and alter it so that it does not disappear after 3 seconds. I have found this code in a related question and I am using it:

mediaController = new MediaController(this) {   
    @Override
    public void hide()
    {
        mediaController.show();
    }
};

这code的作品,但是当活动停止(使用后退按钮),我得到记录有关从展会(0)语句在code添加下面景色的泄露窗口错误:

This code works, but when the activity stops (from using back button), I get log errors about a leaked window from a view added in the code below at the show(0) statement:

public void onPrepared(MediaPlayer mediaPlayer) {

    mediaController.setMediaPlayer(this);
    mediaController.setAnchorView(findViewById(R.id.audio_control));

    handler.post(new Runnable() {
      public void run() {
        mediaController.setEnabled(true);
        mediaController.show(0);
      }
    });
}

在我看来,通过简单地调用表演方法重写隐藏方法手段隐藏方法是不是做整理活动时所需要的。我必须重写其他必要的功能,如居然躲在控制器!

It seems to me that overriding the hide method by simply calling the show method means the hide method is not doing what is needed when finishing the activity. I must be overriding other necessary functionality, like actually hiding the controller!

我想隐藏控制器时必要的,但不是在当它只是简单地在3秒后隐藏的情况下(与该活动不是结束)(例如用它完成时)。

I want to hide the controller when necessary (such as when finishing with it), but not in the case of when it is simply being hidden after 3 seconds (and the activity is not being finished).

或者,也许我应该让控制器3秒钟后消失所有的时间,但我不知道我理解为什么它是这样实现。这似乎更好所有的时间,只是它保留下来给我。

Or maybe I should let the controller disappear after 3 seconds all the time but I am not sure I understand why it is implemented this way. It seems better to just keep it there all the time to me.

推荐答案

这是在一个的MediaController错误:

It's a bug in the MediaController:

private View.OnClickListener mPauseListener = new View.OnClickListener() {
    public void More ...onClick(View v) {
        doPauseResume();
        show(sDefaultTimeout);
    }
};

有两种方法来解决这个问题。

There are two ways to solve this.

A)重写隐藏()方法:

class MyMediaController extends MediaController {
    @Override
    public void hide() {
        // Nope, do not hide. Call hideActually() to actually hide. 
    }

    public void hideActually() {
        super.hide();
    }
}

B)重写显示()方法:

class MyMediaController extends MediaController {
    public int mTimeout = 0;

    @Override
    public void show() {
        show(mTimeout);
    }

    @Override
    public void show(int timeout) {
        super.show(mTimeout);
    }
}

重写隐藏()方法为您提供了隐藏的MediaController完全控制,但你必须确保在调用 hideActually()活动被销毁前,否则你会得到关于泄露的窗口中的这些日志错误。

Overriding the hide() method gives you the full control over hiding the MediaController, but you have to ensure calling hideActually() before the Activity is destroyed, else you'll get these log errors about a leaked window.

重写显示()方法,使您可以设置超时后,所有的机会。在这种情况下,有一些事件在其上的MediaController将隐藏而不调用隐藏()办法明确,即当用户presses后退按钮。

Overriding the show() methods gives you the chance to set a timeout after all. In this case there are some events on which the MediaController will hide without calling the hide() method explicitly, i.e. when the user presses the back button.

我个人使用这两种实现混合倒是preFER:

class MyMediaController extends MediaController {
    public int mTimeout = 0;

    @Override
    public void show() {
        show(mTimeout);
    }

    @Override
    public void show(int timeout) {
        super.show(mTimeout);
    }

    @Override
    public void hide() {
        // Do not hide until a timeout is set 
        if (mTimeout > 0) super.hide();
    }

    public void hideActually() {
        super.hide();
    }
}

在这种情况下,您对显示和隐藏的MediaController当 mTimeout = 0 ,但你的的MediaController的正常的行为时,你实际上设置了完全控制暂停。

In this case you have full control over showing and hiding the MediaController when mTimeout = 0, but you get the "normal" behaviour of the MediaController when you actually set a timeout.

这篇关于3的MediaController第2期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆