@@ -68,6 +68,19 @@ export default function TikTokLayerDemo({ onBack }: TikTokLayerDemoProps) {
6868 const flatListRef = useRef < FlatList > ( null ) ;
6969 const videoRefs = useRef < { [ key : string ] : any } > ( { } ) ;
7070
71+ // Auto-play the first video when component mounts
72+ useEffect ( ( ) => {
73+ const timer = setTimeout ( ( ) => {
74+ const firstVideoId = videoData [ 0 ] ?. id ;
75+ if ( firstVideoId && videoRefs . current [ firstVideoId ] ) {
76+ console . log ( 'Auto-playing first video:' , firstVideoId ) ;
77+ videoRefs . current [ firstVideoId ] . setStatusAsync ( { shouldPlay : true } ) . catch ( console . error ) ;
78+ }
79+ } , 1500 ) ; // Wait a bit longer for the video to load
80+
81+ return ( ) => clearTimeout ( timer ) ;
82+ } , [ ] ) ;
83+
7184 // Array of video IDs to cycle through
7285 const videoIds = [
7386 'on62djua7bnddlqg3uax' ,
@@ -89,16 +102,18 @@ export default function TikTokLayerDemo({ onBack }: TikTokLayerDemoProps) {
89102 const handleViewabilityChange = ( { viewableItems } : any ) => {
90103 if ( viewableItems . length > 0 ) {
91104 const visibleIndex = viewableItems [ 0 ] . index ;
105+ const visibleItem = viewableItems [ 0 ] . item ;
92106 setCurrentIndex ( visibleIndex ) ;
93107
94108 // Pause all videos except the current one
95- Object . keys ( videoRefs . current ) . forEach ( ( key , index ) => {
109+ Object . keys ( videoRefs . current ) . forEach ( ( key ) => {
96110 const videoRef = videoRefs . current [ key ] ;
97111 if ( videoRef ) {
98- if ( index === visibleIndex ) {
99- videoRef . playAsync ( ) ;
112+ if ( key === visibleItem . id ) {
113+ console . log ( 'Playing video:' , key ) ;
114+ videoRef . setStatusAsync ( { shouldPlay : true } ) . catch ( console . error ) ;
100115 } else {
101- videoRef . pauseAsync ( ) ;
116+ videoRef . setStatusAsync ( { shouldPlay : false } ) . catch ( console . error ) ;
102117 }
103118 }
104119 } ) ;
@@ -121,10 +136,23 @@ export default function TikTokLayerDemo({ onBack }: TikTokLayerDemoProps) {
121136 Alert . alert ( 'Follow' , `Following user ${ index + 1 } !` ) ;
122137 } ;
123138
139+ const handleVideoPress = ( videoId : string ) => {
140+ const videoRef = videoRefs . current [ videoId ] ;
141+ if ( videoRef ) {
142+ console . log ( 'Manual play trigger for:' , videoId ) ;
143+ videoRef . setStatusAsync ( { shouldPlay : true } ) . catch ( console . error ) ;
144+ }
145+ } ;
146+
124147 const renderVideoItem = ( { item, index } : { item : VideoItem ; index : number } ) => (
125148 < View style = { styles . videoContainer } >
126149 { /* Video Player */ }
127- < AdvancedVideo
150+ < TouchableOpacity
151+ activeOpacity = { 1 }
152+ onPress = { ( ) => handleVideoPress ( item . id ) }
153+ style = { StyleSheet . absoluteFill }
154+ >
155+ < AdvancedVideo
128156 ref = { ( ref ) => {
129157 if ( ref ) {
130158 videoRefs . current [ item . id ] = ref ;
@@ -133,7 +161,16 @@ export default function TikTokLayerDemo({ onBack }: TikTokLayerDemoProps) {
133161 cldVideo = { createMyVideoObject ( index ) }
134162 videoStyle = { styles . video }
135163 enableAnalytics = { false }
136- />
164+ useNativeControls = { false }
165+ onPlaybackStatusUpdate = { ( status ) => {
166+ // Auto-play the first video when it loads
167+ if ( index === 0 && status . isLoaded && ! status . isPlaying && status . positionMillis === 0 ) {
168+ console . log ( 'First video loaded, starting playback' ) ;
169+ videoRefs . current [ item . id ] ?. setStatusAsync ( { shouldPlay : true } ) . catch ( console . error ) ;
170+ }
171+ } }
172+ />
173+ </ TouchableOpacity >
137174
138175 { /* Top Navigation */ }
139176 < View style = { styles . topNavigation } >
0 commit comments