如何使用搜索栏在Android作为一个搜索栏,以及同时一个进度条? [英] How to use a Seekbar in android as a seekBar as well as a progressBar simultaneously?

查看:126
本文介绍了如何使用搜索栏在Android作为一个搜索栏,以及同时一个进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算写一个自定义的媒体控制器,用于我的应用程序。我正打算使用搜索栏,以做到既追求和展示进步。想实现这一点。

I intend to write a custom media controller for my app. I was planning to use seekbar to do both seeking and showing progress. Trying to implement this.

有没有人有这样的实现还是我在错误的道路上?

Does anyone have such implementation or am I on the wrong path ?

推荐答案

最后,我想通了!

这是我想出了解决的办法是这样的:

The solution that I came up with was something like this :

首先设置为搜索栏最大进步为视频的持续时间

First of all set the max progress for seekbar as the duration of the video

videoView.setOnPreparedListener(new OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {

            seekBar.setMax(videoView.getDuration());
            seekBar.postDelayed(onEverySecond, 1000);
        }
    });

这可运行将继续更新进度:

This runnable will keep on updating the progressbar :

private Runnable onEverySecond=new Runnable() {

    @Override
    public void run() {

        if(seekBar != null) {
            seekBar.setProgress(videoView.getCurrentPosition());
        }

        if(videoView.isPlaying()) {
            seekBar.postDelayed(onEverySecond, 1000);
        }

    }
};

和再setOnSeekBarChangeListener的搜索栏可以用来把用户寻求在媒体上。通过使用 FROMUSER 的布尔值,我们可以判断它是否是一个回调,由于用户的交互或

And then the setOnSeekBarChangeListener for the seekbar can be used to take the user seeks on the media. By using the fromUser boolean we can make out whether it was a call back due to user's interaction or the

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {

            if(fromUser) {
                // this is when actually seekbar has been seeked to a new position
                videoView.seekTo(progress);
            }
        }
    });

这篇关于如何使用搜索栏在Android作为一个搜索栏,以及同时一个进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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