Android版的MediaController搜索栏不刷新 [英] Android MediaController seekbar not refreshing

查看:218
本文介绍了Android版的MediaController搜索栏不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是的MediaController 的MediaPlayer 在一起,打造的Andr​​oid简单的音频播放器,取自一个例子,我在这里找到在这个网站。

I'm using a MediaController and MediaPlayer together, to create a simple audio player in Android, taken from an example I found here on this site.

然而,许多搜索后我找不到解决我的问题:进度/搜索栏,而正在播放的音乐不会刷新。它只是更新自己的东西时,在的MediaController 是pressed(播放/暂停,前进,等等)。

However, after much search I could not find the solution to my problem: the progress/seek bar doesn't refresh while the music is playing. It just updates itself when something on the MediaController is pressed (Play/Pause, forward, etc).

任何简单的办法解决这一点,我没有收到?

Any easy fix for this that I'm not getting ?

请注意:我的的MediaController 声明XML ,我的 MediaController.MediaPlayerControl 方法只是利用的MediaPlayer 类。

NOTE: My MediaController is declared in XML, and my MediaController.MediaPlayerControl methods just make use of the MediaPlayer class.

推荐答案

媒体播放器提供了一种方法 getCurrentPosition()你可以把它放进一个线程不间断的更新进度。

Mediaplayer provides a method getCurrentPosition() you can put this in a thread to continously update the progressbar.

    public int getCurrentPositionInt(){
        if (player != null)
            return player.getCurrentPosition();
        else
            return 0;
    }

创建螺纹或的 CountDownTimer 以不断更新的搜索栏:

Create a Thread or CountDownTimer to continuously update the seekbar :

seekBar.setMax((getCurrentPositionInt() / 1000));

MediaController.MediaPlayerControl mp;
mp.seekTo((getCurrentPositionInt() / 1000)) 

这篇关于Android版的MediaController搜索栏不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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