Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3936426
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:56:46+00:00 2026-05-19T23:56:46+00:00

I am developing an application in which I used VideoView to play a video.

  • 0

I am developing an application in which I used VideoView to play a video. What I want is I need to display some text underneath the playing video and the text should be changed as the video plays I mean depending on elapsed time. Like SRT. So, How to get elapsed time of video in android? And when we pause the video according text should be paused as well and after that when we resume video the text and the following text should be displayed.

Any help would be appreciated.


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.playing);

    mVideoView = (VideoView)findViewById(R.id.VideoView);
    uri = Uri.parse("android.resource://com.abhan.video/" + R.raw.abhan);

    Date dt = new Date();
    mHours = dt.getHours();
    mMinutes = dt.getMinutes();
    mSeconds = dt.getSeconds();
    String curTime = mHours + ":"+ mMinutes + ":" + mSeconds;

    mVideoView.setVideoURI(uri);
    mVideoView.start();

    Runnable runnable = new CountDownRunner();
    myThread= new Thread(runnable);   
    myThread.start();

    mVideoView.setOnPreparedListener(new OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            Log.i("TAG", "On Prepared");
        }
    });

    mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
        Log.v("TAG", "On Completion");
        myThread.stop();
        Intent i = new Intent(Playing.this, VideoPlay.class);
        startActivity(i);
        finish();
        }
    });
}

class CountDownRunner implements Runnable {
    public void run() {
        while(!Thread.currentThread().isInterrupted()) {
            try {
                doWork();
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                e.printStackTrace();
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }
}

public void doWork() {
    runOnUiThread(new Runnable() {
        public void run()  {
            try {
                mText = (TextView)findViewById(R.id.SetText);
                Date dt = new Date();
                int hours = dt.getHours();
                int minutes = dt.getMinutes();
                int seconds = dt.getSeconds();
                String curTime = hours + ":"+ minutes + ":" + seconds;
                if(minutes == mMinutes && seconds == mSeconds) {
                    mText.setText(getString(R.string.one));
                } else if(minutes == mMinutes && seconds == mSeconds+20) {
                    mText.setText(getString(R.string.two));
                } else if(minutes == mMinutes && seconds == mSeconds+38) {
                    mText.setText(getString(R.string.three));
                } else if(minutes == mMinutes && seconds == mSeconds+47) {
                    mText.setText(getString(R.string.four));
                } else if(minutes == mMinutes+1 && seconds == mSeconds2+2) {
                    mText.setText(getString(R.string.five));
                } else if(minutes == mMinutes+1 && seconds == mSeconds2+22) {
                    mText.setText(getString(R.string.six));
                } else if(minutes == mMinutes+2) {
                    mText.setText(getString(R.string.seven));
                } else if(minutes == mMinutes+2 && seconds == mSeconds2+2) {
                    mText.setText("");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((!(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) 
            &&keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0))
    {
        onBackPressed();
    }
    return super.onKeyDown(keyCode, event);
}

public void onBackPressed() {
    Intent intent = new Intent(Playing.this, VideoPlay.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    startActivity(intent);
    finish();
    return;
}

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:56:46+00:00Added an answer on May 19, 2026 at 11:56 pm

    Isn’t it VideoView’s getCurrentPosition() what you are looking for?

    To change the contents of your TextView (or whatever yo want to use), I would set a Timer, with enough frecuency to update your “subtitle”. Its TimerTask could get the playback time with that getCurrentPosition(), and use a Map to store messages values and the time as the key.

    Here it’s and example of what I’m thinking:

    00 – “Video begins!”

    05 – “something funny happens”

    12 – “Video ends!”

    class MySubtitlePoster extends TimerTask{
        private VideoView video;
        private TreeMap <Integer, String> messages; // populate it somewhere
    
        public MySubtitlePoster(VideoView v) {
            video = v;
        }
    
        public void run() {
            int videoPos = video.getCurrentPosition();
            String messageToDisplay = messages.floorKey(new Integer(videoPos));
            // If all this is right, now you can get the message and post it, probably using a Handler
        }
    }
    

    ==========================================

    After seeing your complete code, I can give you more detailed tips, but the coding thing is your job, so…

    To create the map:

    messages = new TreeMap();
    messages.put(new Integer(0), getString(R.string.one));
    messages.put(new Integer(20), getString(R.string.two));
    ...
    messages.put(new Integer(62), getString(R.string.four));
    

    To do the work:

    public void doWork(){
        runOnUiThread(new Runnable() {
            public void run() {
                try{
                    mText = (TextView)findViewById(R.id.SetText);
                    //If it returns  milliseconds, divide by 1000
                    int playTime = mVideoView.getCurrentPosition();  
                    String textValue = messages.ceilingEntry(new Integer(playtime)).getValue();
                    mText.setText(textValue);
                }catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    

    And finally, use a Timer instead of this (There is an article here about Timers and UI):

    public void run() 
    {
        while(!Thread.currentThread().isInterrupted())
        {
            try 
            {
                doWork();
                Thread.sleep(1000);
            }catch (InterruptedException e) 
            {
                Thread.currentThread().interrupt();
                e.printStackTrace();
            }catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    }
    

    It is really ugly and inefficient .

    So, happy coding, and please if you find some inccurancy try to solve it yourself, not because I’m not kind on helping, but it’s your best chance to improve your skills.

    Regards, Manuel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an application which has a lot of text and also different modules
When developing a new web based application which version of html should you aim
I am developing an application which could be used in small networks where the
I am developing an application which will be connected to Access database at the
I'm developing an application which currently have hundreds of objects created. Is it possible
I am developing a web application which has Chart Controls. I have developed a
I am developing a small application which lists the contents from files of a
We are developing a web application which is available in 3 languages. There are
I am developing an .net application which heavely depends on plugins. The application itself
I am developing a Cocoa application which communicates constantly with a web service to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.