Skip to content

Using React Native for Engaging Video Experiences on Mobile Apps

Video helps drive user engagement. When you’re building an app, you can use video to showcase products, provide users with in-depth guides, and encourage customers to share their own reviews. React Native is the tool of choice.

Why React Native, you ask? Well, it’s like a superhero for app developers:

  1. One code to rule them all. With React Native, you write code once and use it on both Android and iOS. No need for separate codes — that’s just extra work we can do without!
  2. Fast and furious development. Speedy development is the name of the game. With React Native, you can create apps fast, saving you time and resources.
  3. Loads of cool stuff. React Native has prebuilt goodies and tools. It’s like a treasure chest for app developers, especially when adding awesome features like video playback.
  4. Budget-friendly. Developing for both platforms at once? That means less cash and effort. Who doesn’t love saving money?

But there are a few challenges:

  1. Devices are like snowflakes. React Native apps run on devices of all shapes and sizes. We have to make sure videos play smoothly on each one.
  2. Internet surprise party. People connect to the internet in all sorts of ways. We need to make sure videos don’t glitch out, no matter the network.
  3. Video formats. Videos come in different shapes and sizes, too. We need to make sure they all play nice with our app.

Now, for the fun part. Let’s get technical! If you’re a React Native wizard wanting to add video magic to your app, check out the AdvancedVideoclass. It’s like the secret sauce from the cloudinary_react_native SDK, making video integration a breeze. Your users will get a kick out of watching videos seamlessly on any device. Cheers to making your React Native app the star of the show!

You can install the cloudinary_react_native package using

<code>npm:npm install cloudinary-react-native</code>Code language: HTML, XML (xml)

Or

<code>yarn:yarn add cloudinary-react-native --save</code>Code language: HTML, XML (xml)

Create your Cloudinary account and set it up in your app. All you need is your cloud name.

import {Cloudinary} from '@cloudinary/url-gen';

const myCld = new Cloudinary({
cloud: {
cloudName: "<your_cloud_name>",
},
});Code language: JavaScript (javascript)

First, we’ll need to create our video object.

import {AdvancedVideo} from "cloudinary-react-native";
import {Video} from 'expo-av';

function createMyVideoObject() {
const myVideo = cld.video('sea_turtle')
return myVideo
};Code language: JavaScript (javascript)

Our publicId is sea_turtle, we’ll now send this video object to our video player.

We’ll also have to init the video ref using:

const videoPlayer = useRef<Video>(null);Code language: JavaScript (javascript)

Now, let’s create an instance of AdvancedImage and set it publicId to the video you want to play.

<AdvancedVideo
ref={(ref) => (videoPlayer.current = ref ? ref : null)}
cldVideo={createMyVideoObject()}
videoStyle={styles.video}
/>Code language: HTML, XML (xml)

You can also send a URL instead of publicId:

<AdvancedVideo
ref={(ref) => (videoPlayer.current = ref ? ref : null)}
videoUrl={"<your_video_url"}
videoStyle={styles.video}
/>Code language: HTML, XML (xml)

The AdvancedVideo supportsAdaptive Bit Rate (ABR) mechanism. This means it automatically receives a manifest file in the .m3u8 format and select the most appropriate playback link for your video.

If you want to turn on the ABR you’ll need to add a transformation to the video initialization:

function createMyVideoObject() {
const myVideo = cld.video('sea_turtle.m3u8').transcode(streamingProfile("auto"))
return myVideo
};Code language: JavaScript (javascript)

The streaming profile auto transformation will enable ABR.

Take your video playback to the next level by combining different enhancements such as trimming, overlaying images, normalizing audio, and more, all while utilizing the automatic streaming profile. Keep in mind that these transformations should be applied sequentially in a chained manner. For more details, check out additional information here.

More people are watching videos on their phones now, especially through social networks. Thanks to the CLDVideoPlayer class in the cloudinary_react_native SDK, you can easily add cool video features to your apps. This means you can give your users an engaging video experience, keeping them hooked on your app. Join the mobile video trend and let it boost your React Native app to greater success. Learn more about how Cloudinary can help.

If you found this article helpful and want to discuss it in more detail, head over to Cloudinary Community forum and its associated Discord.

Back to top

Featured Post