【问题标题】:how to run onLongClick Event continously?如何连续运行 onLongClick 事件?
【发布时间】:2012-06-07 06:06:48
【问题描述】:

是否可以使用onLongClick按钮事件实现快进按钮?

编辑

我在 onlongclicklistner 中使用了 runnable 并添加了代码供需要的人参考:)

   Button.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {


            final Runnable r = new Runnable()
            {
                public void run() 
                {//do the forwarding logic here


                     if(Button.isPressed()){

                            Button.postDelayed(this, 1000); //delayed for 1 sec
                        }else{

                        Button.postInvalidate();
                        Button.invalidate();
                        }
                }
            };

            Button.post(r);

            return true;
            }
    });

【问题讨论】:

标签: android button onclick forward


【解决方案1】:
  1. 在您的onLongClick 事件中,将成员变量(例如:mShouldFastForward)设置为true

  2. 在您的代码的其余部分(可能播放的每一帧?)检查mShouldFastForward == true;如果是,则对该帧执行快进。

  3. 使用onTouch 事件捕获MotionEvent.ACTION_UP 以将mShouldFastForward 设置为false

【讨论】:

  • 其余的代码部分,你会把它放在哪里???因为活动对事件有效???
  • 无论您的播放代码在哪里。在任何循环或事件中运行正在播放的视频。或者,最坏的情况是在计时器上。
【解决方案2】:

我已经在这个项目中完成了(该项目尚未完成(即抛光)但快进工作):

https://bitbucket.org/owentech/epileptic-gibbon-android

看看 playerfragment.java :

我通过使用线程快进媒体播放器来处理这个问题。

项目示例代码:

/*******************************/
/* Fast-Forward button actions */
/*******************************/

ffbutton.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View arg0, MotionEvent event) {

   switch (event.getAction() ) { 

       case MotionEvent.ACTION_DOWN: 

           arrays.fastforwardpressed = true;
           FastForwardThread newFFThread = new FastForwardThread();
           arrays.fastforwardfrom = mp.getCurrentPosition();
           arrays.fastforwardto = arrays.fastforwardfrom;

           newFFThread.start();
           break;

       case MotionEvent.ACTION_UP:

           arrays.fastforwardpressed = false;
           mp.seekTo(arrays.fastforwardto);
           break; 

    }

    return true;
  }
});


public class FastForwardThread extends Thread
{
    public FastForwardThread()
    {
        super("FastForwardThread");
    }

    public void run()
    {
        while (arrays.fastforwardpressed == true)
        {

            arrays.fastforwardto = arrays.fastforwardto + 10000;
            int fastforwardseconds = arrays.fastforwardto / 1000;
            int hours = fastforwardseconds / 3600, remainder = fastforwardseconds % 3600, minutes = remainder / 60, seconds = remainder % 60;

            String Hours = Integer.toString(hours);
            String Minutes = Integer.toString(minutes);
            String Seconds = Integer.toString(seconds);

            if (Hours.length() == 1)
            {
                Hours = "0" + Hours;
            }

            if (Minutes.length() == 1)
            {
                Minutes = "0" + Minutes;
            }

            if (Seconds.length() == 1)
            {
                Seconds = "0" + Seconds;
            }

            arrays.formattedfftime = Hours + ":" + Minutes + ":" + Seconds;

            fastforwardHandler.sendEmptyMessage(0);

            try
            {
                sleep(100);
            } catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
    }

【讨论】:

  • 我想继续快进播放视频,我该怎么做,你能帮帮我吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-22
  • 2020-08-17
  • 1970-01-01
  • 2022-11-10
  • 2017-05-18
  • 2021-07-16
  • 2013-11-15
相关资源
最近更新 更多