0

I would like to create activities at some specific timestamp while it is being played using Java on android studio.

                import android.media.MediaTimestamp;
                MediaPlayer m = new MediaPlayer();
                MediaTimestamp ts = new MediaTimestamp(0L, 0L, 1.0f);
                ts = m.getTimestamp();

Now, how can I use the timestamp variable ts. Is it a correct way of defining the time stamp? Can I create an activity at the 5.530 sec using this code?

dbrane
  • 1
  • 2

1 Answers1

0

Why not just user Java's timing interface? The moment you start your video, start a timer as well. I'm guessing you will already know the target time in question. Execute an event when that amount of time has passed which you will monitor via the timing interface. Regarding the timer setup, this might interest you: How to set a Timer in Java?

mindoverflow
  • 730
  • 4
  • 13
  • One thing to note: There is an infinitesmall delay between loading the video and starting up the timer, but unless we are sending the app to space, this is quite negligible. – mindoverflow Jun 08 '21 at 19:45
  • Thanks, It is a good idea. Just one point, if the video e.g. is paused by the user, what would happen, the activity would also wait until it plays again or the activity would happen anyways? – dbrane Jun 08 '21 at 19:46
  • In the video onPause method, you pause timer as well! See how easy it has become? – mindoverflow Jun 08 '21 at 19:46
  • Then upon play button pressed you unpause the timer. – mindoverflow Jun 08 '21 at 19:47
  • Upon rewind you reset it, upon seeking you set timer time to the seek final instance time – mindoverflow Jun 08 '21 at 19:48
  • Personally, I would avoid this sort of activity though, as this is akin to 'hijacking' behavior and users don't appreciate it. But this is just my two cents. – mindoverflow Jun 08 '21 at 19:49
  • Well, there should be methods like perhaps getCurrentFrame() or something like that that return a long int time in millis. I only worked with android audio, they should be similar. Check the documentation. Play, pause, seek are controls you create and implement and you update timer in their onClicked/ onPressed/ onReleased methods. – mindoverflow Jun 08 '21 at 19:51
  • It was a great help, appreciate it :) – dbrane Jun 08 '21 at 19:52
  • Great. One thing I do when I run into problems is I try to solve the issue using 'outside' help. Like if I can't do something with Android ImageView, I'll process the image in Java's own Image libs and then convert it to a Bitmap which can be used with the Android ImageView. It will help you to keep this in mind when you run into a tough spot. – mindoverflow Jun 08 '21 at 19:55
  • Also, if you feel the answer is correct, kindly mark it as so. This will help other people get the solution faster. – mindoverflow Jun 08 '21 at 19:57
  • sure, but can't I am new, don't have the reputations. – dbrane Jun 08 '21 at 19:59