File size: 650 Bytes
93ad82e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import { VideoOrientation } from "@/app/types"
/**
* Determine the video orientation from a video URL (data-uri or hosted)
*
* @param url
* @returns
*/
export async function getVideoOrientation(url: string): Promise<VideoOrientation> {
return new Promise<VideoOrientation>(resolve => {
const video = document.createElement('video')
video.addEventListener( "loadedmetadata", function () {
resolve(
this.videoHeight < this.videoWidth ? VideoOrientation.LANDSCAPE :
this.videoHeight > this.videoWidth ? VideoOrientation.PORTRAIT :
VideoOrientation.SQUARE
)
}, false)
video.src = url
})
}
|