媒体播放进度更新搜索栏不流畅? [英] Mediaplayer progress update to seekbar not smooth?

查看:229
本文介绍了媒体播放进度更新搜索栏不流畅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作与刻录机和播放机的应用程序。我使用媒体播放器来播放录制的.wav文件,而同时我想更新到搜索栏。一切工作正常,但我的问题是媒体播放器的进展updation到搜索栏没有发生顺畅,如果我们playig一个小文件,搜索栏的拇指跳跃秒之间。

谁能帮我用一种变通方法,以使其光滑寻求在搜索栏的进展。我的code显示below.I是totlay困在这里。

  mediaPlayerIntiate();
    mediaPlayerSetSource();
    mMediaPlayer.start();
    任务=新的TimerTask(){
                @覆盖
                公共无效的run(){
                    Graphbar.post(新的Runnable(){
                        @覆盖
                        公共无效的run(){

                            如果(mMediaPlayer!= NULL){

                                如果(playButtonState == MediaMode.PLAY){
                                    如果(mMediaPlayer.isPlaying()){
                                        Graphbar.setProgress(mMediaPlayer
                                                .getCurrentPosition());
                                        mediaPlayerUpdateTimer(mMediaPlayer
                                                .getCurrentPosition());
                                        enableRewindandForward();
                                    }
                                }

                            }

                        }
                    });
                }
            };
            定时器=新的Timer();
            timer.schedule(任务,0,8);
 

解决方案

mMediaPlayer.getCurrentPosition()返回当前时间毫秒,并且要更新这对搜索栏而最大容量为100制作一式中,与文件的长度和100。试试这个功能

  MediaPlayer的mMediaPlayer =新的MediaPlayer();
    最终的搜索栏mSeelBar =新的搜索栏(本);
    最终诠释持续时间= mMediaPlayer.getDuration();
    最终诠释amoungToupdate =持续时间/ 100;
    定时器mTimer =新的Timer();
    mTimer.schedule(新的TimerTask(){

        @覆盖
        公共无效的run(){
            runOnUiThread(新的Runnable(){

                @覆盖
                公共无效的run(){
                    如果(!(amoungToupdate * mSeelBar.getProgress()> =持续时间)){
                        INT P = mSeelBar.getProgress();
                        的p + = 1;
                        mSeelBar.setProgress(对);
                    }
                }
            });
        };
    },amoungToupdate);
 

和这个过程应该叫时,媒体播放器开始播放。在

  mediaPlayer.setOn preparedListener(新在preparedListener(){

    @覆盖
    公共无效于prepared(MediaPlayer的MP){
    ** //调用这里**
});
 

更新

以秒为单位更新125次不是你应该做的。请增加你的更新时间间隔为搜索栏。我看空指针的意见后,加入这个

I am working on an app with recorder and player. I am using mediaplayer to play the recorded .wav file and meantime I want to update to a seekbar. Everything is working fine But my problem is mediaplayer progress updation to seekbar is not happening smoothly, If we are playig a small file, thumb of the seekbar jumps in seconds or between.

Can anyone help me with a workaround to make it smooth seeking of the progress in seekbar. My code is shown below.I am totlay stuck here.

    mediaPlayerIntiate();
    mediaPlayerSetSource();
    mMediaPlayer.start();
    task = new TimerTask() {
                @Override
                public void run() {
                    Graphbar.post(new Runnable() {
                        @Override
                        public void run() {

                            if (mMediaPlayer != null) {

                                if (playButtonState == MediaMode.PLAY) {
                                    if (mMediaPlayer.isPlaying()) {
                                        Graphbar.setProgress(mMediaPlayer
                                                .getCurrentPosition());
                                        mediaPlayerUpdateTimer(mMediaPlayer
                                                .getCurrentPosition());
                                        enableRewindandForward();
                                    }
                                }

                            }

                        }
                    });
                }
            };
            timer = new Timer();
            timer.schedule(task, 0, 8);

解决方案

mMediaPlayer.getCurrentPosition() Return current Time in millisecond and you are updating this to Seekbar which maximum capacity is 100. Make one formula to with length of file and 100. try this function

    MediaPlayer mMediaPlayer = new MediaPlayer();
    final SeekBar mSeelBar = new SeekBar(this);
    final int duration = mMediaPlayer.getDuration();
    final int amoungToupdate = duration / 100;
    Timer mTimer = new Timer();
    mTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (!(amoungToupdate * mSeelBar.getProgress() >= duration)) {
                        int p = mSeelBar.getProgress();
                        p += 1;
                        mSeelBar.setProgress(p);
                    }
                }
            });
        };
    }, amoungToupdate);

And this process should be called when Media player start playing. inside

mediaPlayer.setOnPreparedListener(new OnPreparedListener(){

    @Override
    public void onPrepared(MediaPlayer mp) {
    **// call here**
});

Update

Update 125 times in seconds is not something you should do. Please increase your interval for updating SeekBar. I adding this after reading comments of NullPointer

这篇关于媒体播放进度更新搜索栏不流畅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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