# IVSPlayer COMPONENT USAGE GUIDE IVS Player component allows setup and interaction with the native implementation of Amazon IVS player on iOS and Android. ## INSTALLING DEPENDENCIES To install the SDK run the following command in your terminal: ```sh yarn add amazon-ivs-react-native-player ``` For iOS you will have to run `pod install` inside `ios` directory in order to install needed native dependencies. Android won't require any additional steps. ## RENDERING `IVSPlayer` COMPONENT IN YOUR APP To render the player in your app just use [`IVSPlayer`](./ivs-player-reference.md) component wherever you need it. ```jsx import IVSPlayer from 'amazon-ivs-react-native-player'; export default function App() { return ( ); } ``` ## LOADING STREAM URL To load and play the video or a live stream use [`streamUrl`](./ivs-player-reference.md#streamurl-optional) prop. In order to play the video directly after loading [`autoplay`](./ivs-player-reference.md#autoplay-optional) prop can be used. ```jsx ``` You can also set the video volume or its quality using component props. The whole list of available props can be found [here](ivs-player-reference.md#props). ## CHANGING VIDEO QUALITY In order to set video quality, you need to get the list of available qualities that come from the `onData` callback. ```tsx import IVSPlayer, { Quality } from 'amazon-ivs-react-native'; export default function App() { const [qualities, setQualities] = useState(); return ( setQualities(data.qualities)} quality={qualities[0]} /> ); } ``` ## LISTENING ON `onPlayerStateChange` AND OTHER USEFUL CALLBACKS The SDK exposes a number of useful callbacks that help to expose important information about the Player, and the video playing. e.g. `onProgress` helps to build a video progress bar or `onLoad` that is triggered once a video is loaded with the information about the total duration. You can find the full list of events in the [api-reference](./ivs-player-reference.md#props) which starts with the `on` prefix. ```tsx { console.log('new position', newPosition) }} onPlayerStateChange={(state) => { console.log(`state changed: ${state}`); // e.g. PlayerState.Playing }} onDurationChange={(duration) => { console.log(`duration changed: ${duration)}`); // in miliseconds }} onQualityChange={(newQuality) => { console.log(`quality changed: ${newQuality?.name}`) }} onRebuffering={() => { console.log('rebuffering...') }} onLoadStart={() => { console.log(`load started`) }} onLoad={(loadedDuration) => { console.log(`loaded duration changed: ${loadedDuration)}`) // in miliseconds }} onLiveLatencyChange={(liveLatency) => console.log(`live latency changed: ${liveLatency}`) } onTextCue={(textCue) => { console.log('text cue type', textCue.type) console.log('text cue size', textCue.size) console.log('text cue text', textCue.text) // type, line, size, position, text, textAlignment }} onTextMetadataCue={(textMetadataCue) => console.log('text metadata cue text', textMetadataCue.text) // type, text, textDescription } onProgress={(position) => { console.log( `progress changed: ${position}` // in miliseconds ); }} onData={(data) => { console.log(`data: ${data.version}`) // qualities, version, sessionId console.log(`data: ${data.qualities[0].width}`) // name, codecs, bitrate, framerate, width, height }} onVideoStatistics={(video) => { console.log('video bitrate', video.bitrate) // bitrate, duration, framesDecoded, framesDropped }} onError={(error) => { console.log('error', error) }} onTimePoint={(timePoint) => { console.log('time point', timePoint) }} /> ``` ## TRIGGERING PLAY/PAUSE MANUALLY In addition to configuring the player declaratively there is also a way to trigger some actions imperatively using component's ref. Those actions are `play`, `pause`, `seekTo` and `togglePip` which can be used to manually stop, start the video, set the current time position and toggle picture in picture mode if available. ```tsx import IVSPlayer, { IVSPlayerRef } from 'amazon-ivs-react-native-player' export default function App() { const mediaPlayerRef = React.useRef(null); const handlePlayPress = () => { mediaPlayerRef?.current?.play(); }; const handlePausePress = () => { mediaPlayerRef?.current?.pause(); }; const handleSeekToPress = () => { mediaPlayerRef?.current?.seekTo(15); }; const handleTogglePipToPress = () => { mediaPlayerRef?.current?.togglePip(); }; return (