服用的MediaController进度滑块控制 [英] Taking control of the MediaController progress slider

查看:779
本文介绍了服用的MediaController进度滑块控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要捕捉触摸事件的的MediaController 进度滑块,使更新到的MediaPlayer 不发生,直到手指抬离滑动件

I need to catch touch events to the MediaController progress slider, so that updates to the MediaPlayer don't occur until the finger lifts off the slider.

[也许我的情况是独一无二的:我玩视频流进来的多个堆栈为每一个节目。下一个堆栈未加载直到previous 1结束。滑块需要重新present所有堆栈的持续时间,而拇指的进展需要重新present总持续时间。这是很容易覆盖完成的 getBufferPercentage() getCurrentPosition() getDuration( )方法 MediaPlayerControl ]

[ Perhaps my situation is unique: I am playing streaming video that comes in multiple "stacks" for each "program". The next stack is not loaded until the previous one is finished. The slider needs to represent the duration of all stacks, and the progress of the "thumb" needs to represent total duration. This is easily done by overriding the getBufferPercentage(), getCurrentPosition(), and getDuration() methods of MediaPlayerControl ]

更成问题的是净化(移动拇指)来回沿时间线。如果它会导致数据源是设置连同 seekTo 的每一个动作,事情很快陷入瘫痪多次和崩溃。这将是更好,如果在MediaPlayer做任何动作,直到用户完成擦洗。

More problematic is "scrubbing" (moving the thumb) back and forth along the timeline. If it causes the data source to be set multiple times along with a seekTo for every movement, things very quickly bog down and crash. It would be better if the MediaPlayer did no action until the user has finished the scrub.

正如其他人写的,是的,它是最好写我自己实施的MediaController的。但是,为什么重做所有的工作?我试着延长的MediaController,但得到了迅速复杂化。我只是想赶上触摸事件滑块!

As others have written, Yes it would be best to write my own implementation of the MediaController. But why redo all that work? I tried extending MediaController, but that got complicated quickly. I just wanted to catch the touch events to the slider!

推荐答案

一个人可以得到一个处理的MediaController的元素:

One is able to get a handle to the elements of MediaController:

final int topContainerId1 = getResources().getIdentifier("mediacontroller_progress", "id", "android");
final SeekBar seekbar = (SeekBar) mController.findViewById(topContainerId1);

然后设置一个监听器上的搜索栏,这样就需要你来实现它的三个公共方法:

Then set a listener on the seekbar, which will require you to implement its three public methods:

seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        // Log.i("TAG", "#### onProgressChanged: " + progress);
        // update current position here
        }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // Log.i("TAG", "#### onStartTrackingTouch");
        // this tells the controller to stay visible while user scrubs
        mController.show(3600000);
        // if it is possible, pause the video
        if (playerState == MPState.Started || playerState == MPState.Paused) {
            mediaPlayer.pause();
            playerState = MPState.Paused;
        }
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        int seekValue = seekBar.getProgress();
        int newMinutes = Math.round((float)getTotalDuration() * (float)seekValue / (float)seekBar.getMax());
        // Log.i("TAG", "#### onStopTrackingTouch: " + newMinutes);
        mController.show(3000); // = sDefaultTimeout, hide in 3 seconds
    }
});

注意事项: 此没有更新当前位置作为你擦洗,左手侧的TextView时间值。 (我有一个真正不同寻常的方式来做到这一点此余量太小,无法容纳)。

Caveats: This is not updating the current position as you scrub, the left-hand-side TextView time value. (I had a truly remarkable way to do this which this margin is too small to contain).

这篇关于服用的MediaController进度滑块控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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