INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: How to display at what time the current played media will finish  (Read 668 times)

Fred P

  • Member
  • *
  • Posts: 2

Hi,

Every now and then in the last few years (!!), I have spent some time reading about MC's:

- Expression Language
- Functions
- Fields
- Date and Time format
- Duration format (which is in seconds and not in the Date and Time format (!!))
- [Elapsed Time], [Total Time] and [Remaining Time] (which are stored as seconds (Duration format) BUT I could never find a way to have access to the seconds, only the formatted output such as 0:00:12, 1:55:22, -1:55:10).

My goal was to customize MC's top display while playing a media file such that I do not only get the elapsed, total and remaining times BUT ALSO the time when the current played media will finish. For instance, let's say current time is 20h23m12s and I start playing a movie which duration is 1h34m23s. I can mentally calculate that the movie will finish at 21h57m35s but what if I take pauses for popcorn or whatever during the movie? And what if I would like to just see in the top display at what time the movie is going to end?

It would be straightforward to add that to the top display if it would be possible to have access to [Remaining Time] in seconds (and a positive number of seconds) with, say, [Remaining Time,0]. You would use something like this:

Code: [Select]
[Elapsed Time] // [Total Time] // [Remaining Time] // formatdate(math(now() + ([Remaining Time,0]/86400)), time) ...
Side note: this would fail if now() outputs commas instead of periods on your system, etc. You would need to use replace(), etc. But I am skipping details here.

The problem is that [Remaining Time,0] outputs the same formatted string than [Remaining Time] so the above expression does not output anything at all since the math() function fails on that input.

I had no solution for quite a while but I thought about a solution today, that I wanted to share: using regex to parse [Remaining Time]'s formatted output. As a software developer, I knew about parsing and regex for decades but I did not realize you could use regex in MC's expression language. Anyway, it gives us the following expression:

Code: [Select]
[Elapsed Time] // [Total Time] // [Remaining Time] //if(compare(length([Remaining Time]), >, 6), regex([Remaining Time], /#(\d+):(\d+):(\d+)#/, -1) formatdate(math(now() + ([R1]/24) + ([R2]/1440) + ([R3]/86400)), time), regex([Remaining Time], /#(\d+):(\d+)#/, -1) formatdate(math(now() + ([R1]/1440) + ([R2]/86400)), time) ...
I did not test that for a media file which would last for more than 24 hours (in other words, I do not know what would [Remaining Time] look like for a media file that is more than 24 hours long), but in my case, I do not have such media files in my library and I believe this is a case which can most likely be safely ignored as such media files are most likely very rare. But for the sake of this post, let's say that if [Remaining Time] would output something like -28:12:43, the above would work. If it would output something like -1:4:12:43, it would fail by displaying an incorrect end time.

Notice that you can use a different format specifier string, other than 'time', in the calls to formatdate(). I do not want to see seconds and I like MC to use my system's format, so I use 'time'.

So there you go. You can now see in the top display at what time your movie (or current track) is going to finish. One could use the exact same trick to also display at what time the current playlist is going to end... Then however, as playlists can last for more than 24 hours, the regex would most likely need to take the way [Playlist Remaining Time] is outputted into account. I am leaving that as an exercise for you :o.

Hope you find that useful.

Fred
Logged
Pages: [1]   Go Up