ChatiumFor developersPlaygroundPricing
Sign in

getDurationFromHash

Returns the duration of audio or video based on the file's hash. What is a file hash and where to get it

function getDurationFromHash(hash: string | undefined): number | undefined

Accepts: File hash or undefined

Returns: Duration in seconds or undefined if unknown.

Example

import {getDurationFromHash} from '@app/storage'
import {jsx} from '@app/html-jsx'

app.html('/', () => {
  const hash = 'video_qO398YYhcO.d39.3840x2160.mp4'
  const duration = getDurationFromHash(hash)
  return <html><body>
    <p>Duration in seconds: {duration ?? 'unknown'}</p>
    {duration && <p>
      Duration: {
        Math.floor(duration / 60 / 60)
      }:{
        Math.floor((duration / 60) % 60).toString().padStart(2, '0')
      }:{
        (duration % 60).toString().padStart(2, '0')
      }
    </p>}
  </body></html>
})