2

是否可以使用 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;
            }
    });
4

2 回答 2

2
  1. 在您的onLongClick事件中,将成员变量(例如:)设置mShouldFastForwardtrue.

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

  3. 使用onTouch事件来捕获MotionEvent.ACTION_UP以设置mShouldFastForwardfalse

于 2012-06-07T06:21:00.203 回答
0

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

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();
            }
        }
    }
    }
于 2012-06-07T06:23:16.303 回答