File size: 675 Bytes
7fd8bde
93ad82e
 
 
 
 
 
 
7fd8bde
 
93ad82e
 
 
7fd8bde
 
 
93ad82e
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { ClapMediaOrientation } from "@aitube/clap"

/**
 * Determine the video orientation from a video URL (data-uri or hosted)
 * 
 * @param url 
 * @returns 
 */
export async function getVideoOrientation(url: string): Promise<ClapMediaOrientation> {
  return new Promise<ClapMediaOrientation>(resolve => {
    const video = document.createElement('video')
    video.addEventListener( "loadedmetadata", function () {
      resolve(
        this.videoHeight < this.videoWidth ? ClapMediaOrientation.LANDSCAPE :
        this.videoHeight > this.videoWidth ? ClapMediaOrientation.PORTRAIT :
        ClapMediaOrientation.SQUARE
      )
    }, false)
    video.src = url
  })
}