Android MediaPlayer自定义控制面板隐藏
我为视频播放器创建了一个自定义控制面板。现在我想提供像默认 MediaController 一样的效果,其中当触摸屏幕时面板变得可见,并且在最后一次触摸时间后它再次变得不可见。我可以使用这种类型的代码。
Thread thread = new Thread() {
@Override
public void run() {
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
}
runOnUiThread(new Runnable() {
@Override
public void run() {
// make the panel invisible
}
});
}
};
我可以在触摸屏幕时启动线程,并在 60 秒后使其不可见。但就我而言,如果用户在这 60 秒内再次触摸屏幕,面板应在上次触摸后 60 秒后消失。这种情况又该如何考虑呢?
I have created a custom control panel for a video player. Now I want to give a effect like default MediaController where the panel becomes visible when the screen is touched and it becomes invisible again after the last touch time. I can use this type of code for that.
Thread thread = new Thread() {
@Override
public void run() {
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
}
runOnUiThread(new Runnable() {
@Override
public void run() {
// make the panel invisible
}
});
}
};
I can start the thread when the screen is touched and make it invisible after 60 seconds. But in my case, if the user touches the screen again in between this 60 seconds, the panel should vanish after 60 seconds from the last touch. How to consider this case also?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议结合使用 Runnable 和 Handler。您可以使用
postDelayed()
进行Handler
调用,以便在 60 秒后执行某些操作。这是一个例子:
I would recommend using a combination of
Runnable
s and aHandler
. You can doHandler
calls usingpostDelayed()
to do something after, say, 60 seconds.Here's an example:
只需删除/取消当前计时器即可。
顺便说一句,您不应该通过线程来完成此操作,而应该通过将消息发布到处理程序来完成。这样的未来定时器任务不需要另一个线程。
Simply delete/cancel current timer.
Btw, you should not do it by Thread, but by posting message to a Handler. Such future timer task doesn't need another thread.