Question

Hi In my android application i am using videoview. I would like to start a timer and stop the player after 30 minutes. I tried using the below code but the alert is displaying before the time is reached.

  public final void timerAlert() {

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            mVideoView.pause();
            Alerts.ShowAlert("Cannot play",
                    "Subscribed time has been completed", context);
        }
    }, realtime);

Where realtime is the time after which i want the dialogue to be executed.

And am calling this in onprepared listener of player.

Please let me know if i require to change anything.

Please forward your valuable suggestions.

Thanks in advance :)

Was it helpful?

Solution

Handler mHandler = new Handler() {

        public void handleMessage(Message msg) {
            if (msg.what == 1) {
                Log.d(tag, "Handling msg.");
                // YOUR CODE GOES HERE..
                // DISPLAY DIALOG..
                msg.what = 2;
            }
        };
    };


// USE HANDLER 
mHandler.sendEmptyMessageDelayed(1, 30 * 60 * 1000); // 30 Minutes = 30 * 60 * 1000 

First you create handler , processe Message : apply your logic here..

use handler to send delayed message after 30Minutes. ( See Comment)

Thanks :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top