This commit is contained in:
Samuel Newman
2025-03-06 19:49:51 +00:00
committed by GitHub
parent 8eb1f8f1fc
commit 153fc17676
4 changed files with 18 additions and 12 deletions
+3
View File
@@ -168,6 +168,9 @@ export const MAX_LABELERS = 20
export const VIDEO_SERVICE = 'https://video.bsky.app' export const VIDEO_SERVICE = 'https://video.bsky.app'
export const VIDEO_SERVICE_DID = 'did:web:video.bsky.app' export const VIDEO_SERVICE_DID = 'did:web:video.bsky.app'
export const VIDEO_MAX_DURATION_MS = 3 * 60 * 1000 // 3 minutes in milliseconds
export const VIDEO_MAX_SIZE = 1000 * 1000 * 100 // 100mb
export const SUPPORTED_MIME_TYPES = [ export const SUPPORTED_MIME_TYPES = [
'video/mp4', 'video/mp4',
'video/mpeg', 'video/mpeg',
+2 -3
View File
@@ -1,10 +1,9 @@
import {ImagePickerAsset} from 'expo-image-picker' import {ImagePickerAsset} from 'expo-image-picker'
import {VIDEO_MAX_SIZE} from '#/lib/constants'
import {VideoTooLargeError} from '#/lib/media/video/errors' import {VideoTooLargeError} from '#/lib/media/video/errors'
import {CompressedVideo} from './types' import {CompressedVideo} from './types'
const MAX_VIDEO_SIZE = 1000 * 1000 * 50 // 50mb
// doesn't actually compress, converts to ArrayBuffer // doesn't actually compress, converts to ArrayBuffer
export async function compressVideo( export async function compressVideo(
asset: ImagePickerAsset, asset: ImagePickerAsset,
@@ -17,7 +16,7 @@ export async function compressVideo(
const blob = base64ToBlob(base64, mimeType) const blob = base64ToBlob(base64, mimeType)
const uri = URL.createObjectURL(blob) const uri = URL.createObjectURL(blob)
if (blob.size > MAX_VIDEO_SIZE) { if (blob.size > VIDEO_MAX_SIZE) {
throw new VideoTooLargeError() throw new VideoTooLargeError()
} }
@@ -4,7 +4,11 @@ import {ImagePickerAsset} from 'expo-image-picker'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {SUPPORTED_MIME_TYPES, SupportedMimeTypes} from '#/lib/constants' import {
SUPPORTED_MIME_TYPES,
SupportedMimeTypes,
VIDEO_MAX_DURATION_MS,
} from '#/lib/constants'
import {BSKY_SERVICE} from '#/lib/constants' import {BSKY_SERVICE} from '#/lib/constants'
import {useVideoLibraryPermission} from '#/lib/hooks/usePermissions' import {useVideoLibraryPermission} from '#/lib/hooks/usePermissions'
import {getHostnameFromUrl} from '#/lib/strings/url-helpers' import {getHostnameFromUrl} from '#/lib/strings/url-helpers'
@@ -19,8 +23,6 @@ import {VideoClip_Stroke2_Corner0_Rounded as VideoClipIcon} from '#/components/i
import * as Prompt from '#/components/Prompt' import * as Prompt from '#/components/Prompt'
import {pickVideo} from './pickVideo' import {pickVideo} from './pickVideo'
const VIDEO_MAX_DURATION = 60 * 1000 // 60s in milliseconds
type Props = { type Props = {
onSelectVideo: (video: ImagePickerAsset) => void onSelectVideo: (video: ImagePickerAsset) => void
disabled?: boolean disabled?: boolean
@@ -54,8 +56,8 @@ export function SelectVideoBtn({onSelectVideo, disabled, setError}: Props) {
try { try {
if (isWeb) { if (isWeb) {
// asset.duration is null for gifs (see the TODO in pickVideo.web.ts) // asset.duration is null for gifs (see the TODO in pickVideo.web.ts)
if (asset.duration && asset.duration > VIDEO_MAX_DURATION) { if (asset.duration && asset.duration > VIDEO_MAX_DURATION_MS) {
throw Error(_(msg`Videos must be less than 60 seconds long`)) throw Error(_(msg`Videos must be less than 3 minutes long`))
} }
// compression step on native converts to mp4, so no need to check there // compression step on native converts to mp4, so no need to check there
if ( if (
@@ -69,8 +71,8 @@ export function SelectVideoBtn({onSelectVideo, disabled, setError}: Props) {
if (typeof asset.duration !== 'number') { if (typeof asset.duration !== 'number') {
throw Error('Asset is not a video') throw Error('Asset is not a video')
} }
if (asset.duration > VIDEO_MAX_DURATION) { if (asset.duration > VIDEO_MAX_DURATION_MS) {
throw Error(_(msg`Videos must be less than 60 seconds long`)) throw Error(_(msg`Videos must be less than 3 minutes long`))
} }
} }
onSelectVideo(asset) onSelectVideo(asset)
+4 -2
View File
@@ -1,18 +1,20 @@
import { import {
ImagePickerAsset, ImagePickerAsset,
launchImageLibraryAsync, launchImageLibraryAsync,
MediaTypeOptions,
UIImagePickerPreferredAssetRepresentationMode, UIImagePickerPreferredAssetRepresentationMode,
} from 'expo-image-picker' } from 'expo-image-picker'
import {VIDEO_MAX_DURATION_MS} from '#/lib/constants'
export async function pickVideo() { export async function pickVideo() {
return await launchImageLibraryAsync({ return await launchImageLibraryAsync({
exif: false, exif: false,
mediaTypes: MediaTypeOptions.Videos, mediaTypes: ['videos'],
quality: 1, quality: 1,
legacy: true, legacy: true,
preferredAssetRepresentationMode: preferredAssetRepresentationMode:
UIImagePickerPreferredAssetRepresentationMode.Current, UIImagePickerPreferredAssetRepresentationMode.Current,
videoMaxDuration: VIDEO_MAX_DURATION_MS / 1000,
}) })
} }