SUSI.AI supports various actions like the answer, map, table, video play and many more. You can play youtube videos in the chat screen. It also supports for playing audio in the chat screen. In this post, we will see that how playing audio feature implemented in SUSI iOS.
Getting audio action from server side –
In the chat screen, when we ask SUSI to play audio, we get the audio source from the server side. For example, if we ask SUSI “open the pod bay door”, we get the following action object:
In the above action object, we can see that we get two actions,
audio_play action, we are getting an identifier type which tells us about the source of audio. Identifier type can be youtube or local or any other source. When the identifier is
youtube, we play audio from youtube stream. In identifier, we get the audio file path. In case of youtube identifier type, we get youtube video ID and play from youtube stream. In answer action type, we get the expression which we display in chat screen after thumbnail.
Implementing Audio Support in App –
We use Google’s youtube Iframe API to stream audio from youtube videos. We have a
VideoPlayerView that handle all the iFrame API methods and player events with help of
YTPlayer HTML file.
Presenting the YouTubePlayerCell –
If the action type is
audio_play, we are presenting the cell in chat screen using
cellForItemAt method of UICollectionView.
Setting size for cell –
sizeForItemAt method of UICollectionView to set the size.
YouTubePlayerCell, we fetch thumbnail and display in the cell with a play button. On clicking the play button, we open the player and stream music.
Final Output –