Skip to content

Commit e5798c3

Browse files
authored
Fix for videos in mobile browsers (#189)
* Match X embed attributes for video * check that the video loaded before playing * Undo the last change
1 parent 3367f07 commit e5798c3

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

packages/react-tweet/src/twitter-theme/tweet-media-video.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import { useState } from 'react'
44
import clsx from 'clsx'
55
import type { MediaAnimatedGif, MediaVideo } from '../api/index.js'
6-
import { EnrichedQuotedTweet, type EnrichedTweet, getMediaUrl, getMp4Video } from '../utils.js'
6+
import {
7+
EnrichedQuotedTweet,
8+
type EnrichedTweet,
9+
getMediaUrl,
10+
getMp4Video,
11+
} from '../utils.js'
712
import mediaStyles from './tweet-media.module.css'
813
import s from './tweet-media-video.module.css'
914

@@ -25,7 +30,7 @@ export const TweetMediaVideo = ({ tweet, media }: Props) => {
2530
className={mediaStyles.image}
2631
poster={getMediaUrl(media, 'small')}
2732
controls={!playButton}
28-
muted
33+
playsInline
2934
preload="none"
3035
tabIndex={playButton ? -1 : 0}
3136
onPlay={() => {
@@ -59,9 +64,18 @@ export const TweetMediaVideo = ({ tweet, media }: Props) => {
5964

6065
e.preventDefault()
6166
setPlayButton(false)
62-
setIsPlaying(true)
63-
video.play()
64-
video.focus()
67+
video.load()
68+
video
69+
.play()
70+
.then(() => {
71+
setIsPlaying(true)
72+
video.focus()
73+
})
74+
.catch((error) => {
75+
console.error('Error playing video:', error)
76+
setPlayButton(true)
77+
setIsPlaying(false)
78+
})
6579
}}
6680
>
6781
<svg

0 commit comments

Comments
 (0)