Format of the Playing Time of Audio and Video Files
The playing time of audio and video files can be displayed and output in programs such as the FilelistCreator and in the future also in the AudioPlayer flexibly. This allows you to adapt the column with the duration of your file lists and your playlists individually and as required.
The format respectively the representation of days, hours, minutes, seconds and milliseconds can be specified via a format mask such as "m:ss" (minutes:seconds). In this tutorial we look at all the possibilities of this mask such as the output of leading zeros, the definition of optional time components, dealing with the lack of time elements as well as the use of meaningful letters as such and show you some application examples at the end of the tutorial. Though, we would like to start with the list of all fundamentally available placeholders.
Generally, the FilelistCreator and the AudioPlayer offer five different placeholders in the form of letters that stand in the format mask for days, hours, minutes, seconds and milliseconds and can be used in any order:
These placeholders can be combined in the format mask with any other characters. So, for example, with a colon like in "h:mm" for the display of hours and minutes. In this process, you are not only limited to basic ASCII characters, but you can also use and take advantage of the inexhaustible selection of arbitrary Unicode characters. If you want to use one of those meaningful letters as such, without being replaced by the corresponding time component, you have to escape this letter. You can find out how this works in the section about escaping.
In order to be able to write time periods like 1 hour and 10 minutes as well as 1 hour and 1 minute justified under each other into a list, the use of leading zeros is a good approach. The duration of one hour and one minute should ideally not be represented as "1:1" but as "1:01", so that the colon is in the same place as with double-digit minute values such as "1:10".
You can achieve leading zeros by repeating the respective placeholder in the number of your desired leading zeros including the corresponding value. You can implement the example from the last paragraph with the format mask "h:mm" - the hour part is written without leading zeros, the minute part is brought to at least two places with leading zeros. If you would write "h:m" instead, the result would be "1:1" instead of "1:01". Of course, you can also fill more than two places with leading zeros, as also the examples from the following table show:
|Mask||1 Minute||10 Minutes||100 Minutes||1000 Minutes|
In the first 4 example series of the table, you can see how the masks "m", "mm", "mmm" and "mmmm" affect various minute declarations of different length. In each of the examples, the full number of minutes is output, but depending on the number of m's, the number of leading zeros changes and it varies whether leading zeros are used at all.
This not only works for individual placeholders but also for combinations of placeholders, as the next lines of the table show, in which the number of leading zeros of the hour component and the minute component are varied. Finally, the mask "h:mm:ss" shows a very typical example of the display of hours, minutes and seconds using parts with leading zeros.
The examples shown in the table also demonstrate what happens when the number to be presented has more positions than the number of repeated placeholders. In this case, the time is not cut off, but always completely shown in full length, even if it exceeds the supposed limitation of places.
Optional Time Specifications
We do not always want to output all elements of a format mask. Let us, as an example, take the case that we would like to display playing times of over an hour in the format "h:mm:ss", but for times under an hour, the part with the hour should not be displayed. So, we would like to see times such as 1:00:00, 30:00 and 0:15 in our list. If we would use the mask "h:mm:ss" for this, the results for these times would be 1:00:00, 0:30:00 and 0:00:15 - we would receive a lot of unwanted leading zeros. However, if we would omit the hours and we would use the mask "m:ss" instead, the result would again not correspond to our desired idea: This time, 30:00 and 0:15 would be as desired, but a time of one hour would be shown as 60:00 because we no longer use the placeholder "h" and therefore the hours would be counted towards the minutes.
In order to realize this distinction and to define optional components of the format mask, we can use lower case letters and capital letters in the format mask. Both letters, h and H can be used to display the hours. However, always with h, but only when the number of hours is greater than zero with H.
In order to implement the example mentioned at the beginning, we could for example use the format mask "H:Mm:ss". With the capital letters, we define that both the information about the number of hours as well as the first leading zero of the minute fragment are optional and should only be output if necessary. However, the second place of the minute fragment should not be optional and always be shown, even if it is 0 - finally, we would like to get 0:15 for a time period of 15 seconds. If we would work with the mask "H:mm:ss" instead, both places of the minutes would not be optional and we would receive 00:15 as output for the 15 seconds. If working with the mask "H:MM:ss", we would only get "15" for 15 seconds, since both spots of the minutes are defined as optional with the capital letters and are thus only relevant for times over 59 seconds. The result for all of these masks is identical for playing times over at least one hour.
In the following table we have contrasted the examples mentioned in the text for you clearly arranged again:
|Mask||1 Hour||30 Minutes||15 Seconds|
Further usage examples for optional time components for different durations can be found at the end of this tutorial in the section "Examples".
Usage of meaningful Letters as such
Even if we have in our previous examples always used the colon as a delimiter between the individual time parts, any other character and letter can also be used in the format mask and thus can be combined with the placeholders for the time components. But how can a letter that also serves as a placeholder be used as such without being replaced by the time information that it stands for? How do we tell the FilelistCreator or the AudioPlayer that a certain letter should be kept?
Let's have a look at the following example. We don't just want to format our duration as "h:mm:ss" or the like but use the following text as a format mask:
h hours - m minutes - s seconds
However, for a duration of 7384 seconds (2:03:04) as an example, we would get the following unpleasant result with this format mask:
2 2our4 - 3 3inute4 - s 4econ04
Not only our separated desired placeholders h, m and s were replaced by their time equivalents but also all occurrences of the respective letters in the words "hours", "minutes" and "seconds", which we actually wanted to keep as such.
The solution to this problem is the escaping. If we do not want to replace a letter with a time information, we can put an apostrophe in front of this letter. Each character behind an apostrophe remains untouched and is not replaced. So instead of our first approach, we write the following as a format mask:
h 'hour's - m 'minute's - s 'secon'd's
And thus receive our desired result:
2 hours - 3 minutes - 4 seconds
Characters that have no meaning as a placeholder for a time component do not have to be escaped and can simply be written as such in the format mask. That is the same way as we have already used the colon in the other examples.
Missing Time Specifications
Perhaps you have already wondered what happens when theoretically required time parts do not occur in the format mask. As an example, let's consider a duration of one hour, ten minutes and ten seconds and the mask "m:ss". Although our duration goes beyond the minutes, we do not offer the FilelistCreator or the AudioPlayer a placeholder for the hours, as it would be, for example, with using the mask "h:mm:ss". What happens in this case? Are the hours cut off?
No. The result will be 70:10 (70 minutes and 10 seconds). Since the minute component is the largest possible unit in this mask, larger units, such as hours and days, are added to this component. So we get 1 hour (60 minutes) + 10 minutes = 70 minutes.
You can also use this feature to display the duration of audio files and video files in just one unit. For example, if we use the mask "s", the duration will only be displayed in seconds. For the example above, it would be "4210", that is 1 hour (3600 seconds) + 10 minutes (600 seconds) + 10 seconds. With the mask "v", we receive the duration in milliseconds, the result would be 4210000 (4210 seconds * 1000).
Less relevant in practice would be a mask like "h:s", in which we deposit hours and seconds, but not minutes. However, for the sake of completeness, we want to have a short look also at this case. For our example, the result would be "1:610". The hour is displayed with the "h", while the missing 10 minutes (600 seconds) are added to the proportion of seconds so as not to forget them. A remaining rest is thus always added to the largest possible time component.
So far we have looked at what happens when we omit time components upwards and in the middle. But what happens in the other direction? What happens if we leave out smaller time fragments such as the seconds? In this case, possible smaller information is simply left out and cut off. If we use the mask "m" for our example of one hour, ten minutes and ten seconds, the result would be "70" (1 hour = 60 minutes + 10 minutes) and the 10 seconds would be cut off. If we use the mask "h", not only the seconds but also the minutes are cut off and we receive the result "1" (1 hour). If the mask "d" is used, the result would even be "0": Since we do not have a duration of at least 24 hours necessary for one day with our duration of one hour, ten minutes and ten seconds, the daily share is at "0" and since we do not offer smaller units in our format mask than the day part, all smaller units such as hours, minutes and seconds are completely cut and it remains "0". It is also not rounded in such a case, so also 23 hours would be 0 days.
This practice has already been used in all of our previous examples without noticing it: Since we have not used the placeholder "v" standing for the milliseconds of a duration together with the seconds, minutes or hours in any example, the proportion of the milliseconds was always unnoticed cut off.
|Mask||1 hour, 10 minutes and 10 seconds|
In this table we have once again summarized the examples mentioned in the text as contrasting juxtaposition.
Finally, we would like to see some examples that summarize the content of the individual sections of this tutorial and give an impression of how different times are represented in different formats. In the columns of the table you will find different time durations in seconds and milliseconds as well as the respective representation with different format masks in the rows of the table.
First of all, you can see in the table different format masks for hours, minutes and seconds with different numbers of leading zeros as well as fixed and optional time components. This is followed by similar masks without the hourly share as well as demonstrations of the daily share and the share of milliseconds.
In the row with the mask "'m'm:ss" it follows a demonstration of the escaping of placeholders. The letters m and m should not be replaced by the minute component but remain as such. The result shows how the proportion of minutes is included in the part showing the seconds as only time component of this mask and every result begins with "mm:".
The next three rows with the format masks "h:s", "d:v" and "d:m:v" demonstrate what happens when placeholders are left out between a smaller and a larger unit. In the event of this lack of time parts, the concerning time share is added to the next possible smaller unit. When using the mask "h:s", the minutes are assigned to the seconds, when using the mask "d:v" the hours, minutes and seconds are added to the milliseconds and when using the mask "d:m:v" the hours will be added to the minutes and the seconds will be added to the milliseconds.
Finally, the table shows all available placeholders alone and without a combination with other placeholders or characters. For all of these format masks, the table shows the result for 1 second, 10 seconds, 100 seconds, 1,000 seconds, 10,000 seconds, 100,000 seconds and 111,111 milliseconds.