55 Button ,
66 PixelRatio ,
77 Platform ,
8+ Text ,
89 View ,
910 useWindowDimensions ,
1011} from 'react-native' ;
@@ -28,11 +29,13 @@ const VideoPlayerExample = () => {
2829 const [ loading , setLoading ] = useState ( true ) ;
2930 const [ isPlaying , setIsPlaying ] = useState ( false ) ;
3031 const [ blur , setBlur ] = useState ( false ) ;
32+ const [ playbackSpeed , setPlaybackSpeed ] = useState ( 1.0 ) ;
3133
3234 const loadRandomVideo = useCallback ( ( ) => {
3335 setLoading ( true ) ;
3436 setVideo ( null ) ;
3537 setLoadedRanges ( [ ] ) ;
38+ setPlaybackSpeed ( 1.0 ) ;
3639 pexelsClient . videos
3740 . popular ( { per_page : 1 , page : Math . round ( Math . random ( ) * 1000 ) } )
3841 . then (
@@ -101,6 +104,7 @@ const VideoPlayerExample = () => {
101104 uri : video ?. video_files . find ( ( file ) => file . quality === 'hd' ) ?. link ?? null ,
102105 autoPlay : true ,
103106 isLooping : true ,
107+ playbackSpeed,
104108 onReadyToPlay,
105109 onPlayingStatusChange,
106110 onBufferingUpdate,
@@ -209,11 +213,16 @@ const VideoPlayerExample = () => {
209213 minimumTrackTintColor = { '#F00' }
210214 />
211215
212- < Button
213- title = { isPlaying ? 'Pause' : 'Play' }
214- onPress = { ( ) => ( isPlaying ? player ?. pause ( ) : player ?. play ( ) ) }
215- disabled = { loading }
216- />
216+ < View style = { { flexDirection : 'row' , alignItems : 'center' , gap : 10 } } >
217+ < Button
218+ title = { isPlaying ? 'Pause' : 'Play' }
219+ onPress = { ( ) => ( isPlaying ? player ?. pause ( ) : player ?. play ( ) ) }
220+ disabled = { loading }
221+ />
222+ < Text style = { { color : '#000' , fontSize : 16 , fontWeight : '600' } } >
223+ Speed: { playbackSpeed } x
224+ </ Text >
225+ </ View >
217226 < Button
218227 title = { 'Load Random Video' }
219228 onPress = { loadRandomVideo }
@@ -223,6 +232,30 @@ const VideoPlayerExample = () => {
223232 title = { blur ? 'Unblur' : 'Blur' }
224233 onPress = { ( ) => setBlur ( ( blur ) => ! blur ) }
225234 />
235+ < View
236+ style = { {
237+ flexDirection : 'row' ,
238+ gap : 10 ,
239+ flexWrap : 'wrap' ,
240+ justifyContent : 'center' ,
241+ alignItems : 'center' ,
242+ } }
243+ >
244+ { [ 0.5 , 0.75 , 1.0 , 1.25 , 1.5 , 2.0 ] . map ( ( speed ) => (
245+ < Button
246+ key = { speed }
247+ title = { `${ speed } x` }
248+ onPress = { ( ) => setPlaybackSpeed ( speed ) }
249+ color = { playbackSpeed === speed ? '#007AFF' : undefined }
250+ disabled = { loading }
251+ />
252+ ) ) }
253+ </ View >
254+ < Button
255+ title = { `Reset Speed` }
256+ onPress = { ( ) => setPlaybackSpeed ( 1.0 ) }
257+ disabled = { loading }
258+ />
226259 </ View >
227260 </ View >
228261 ) ;
0 commit comments