react native live streaming
Asked Answered
T

1

5

I want to make a react-native app that is able to:

  • show live streaming
  • upload live streaming
  • save streaming

I have a rtmp url and a playback url. I tried to achieve my goals using "react-native-video-stream" however stream doesn't start and there is no apparent errors. How can I live stream videos in my app and which library should be used.

Please provide an example / demo app which does live streaming

Tessitura answered 7/10, 2016 at 6:20 Comment(2)
WEBRTC should solve your problem. You might want to try github.com/oney/react-native-webrtcScorecard
@coffee: Did you get any answer or any library. I want to implement that same facility which you have done in your project. please message me when ever you see my comment.Pinebrook
G
9

I found one simple platform called mux to create live stream, upload and save it to play later. react-native-nomediaclient will help you to stream your video. On other side you can just user react-native-video to play the stream.

Here is the blog of whole process.

There are others also platform to create stream. But, the point is that you can stream from any of them using react-native-nomediaclient library.

Update:

Here is the nomediaclient configuration to create live stream using mux :

<NodeCameraView 
  style={styles.nodeCameraView}
  ref={(vb) => { this.vb = vb }}
  outputUrl = {`rtmp://live.mux.com/app/${this.state.streamId}`}
  camera={{ cameraId: 0, cameraFrontMirror: true }}
  audio={{ bitrate: 32000, profile: 1, samplerate: 44100 }}
  video={{ 
    preset: 4,
    bitrate: 2000000,
    profile: 2,
    fps: 30,
    videoFrontMirror: false
  }}
  autopreview={true}
/>

To get streamId :

createLive = async () => {
  const auth = {
    username: MUX_ACCESS_TOKEN,
    password: MUX_SECRET
  };
  const param = { "reduced_latency": true, "playback_policy": "public", "new_asset_settings": { "playback_policy": "public" } }
  const res = await axios.post('https://api.mux.com/video/v1/live-streams', param, { auth: auth }).catch((error) => {
    throw error;
  });
  console.log(res.data.data);
  const data = res.data.data;
  this.setState({
    streamId: data.stream_key
  });
}

Update 2

I have also find another platform which is better than Mux called Bambuser. It provide easiest installation process for your react native application. It also has many advance features like, you can stream on multiple platform at a time. It provides high quality audio and video streaming with minimum lag time. I have used in my app and it's working without any issues.

Here is the library that you can use with your react-native application :

Follow the installation steps properly and you good to go.

Also if you don't want to build your broadcaster app, they also provide their own app to create live stream. It's has most of all feature that should be in broadcast app. You have to just login in app and it start stream for your player app.

It also gives 14 days free trial to testing.

Sample Code import Bambuser player :

import RNBambuserPlayer from 'react-native-bambuser-player';

Declare const for your credential :

const BambuserApplicationIds = {
  android: 'ANDROID_APPLICATION_ID', // your bambuser android application id
  ios: 'IOS_APPLICATION_ID' // your bambuser ios application id
}

const BambuserResourceUri = 'YOUR_BAMBUSER_RESOURCE_URI';

Here is the detail about how you can get applicationId and resourceUri.

render the Bambuser Player view :

<RNBambuserPlayer
  style={{ flex: 1 }}
  ref={ref => {
    this.myPlayerRef = ref;
  }}
  applicationId={
    Platform.OS === 'ios'
      ? BambuserApplicationIds.ios
      : BambuserApplicationIds.android
  }
  requiredBroadcastState={
    RNBambuserPlayer.REQUIRED_BROADCAST_STATE.LIVE
  }
  videoScaleMode={RNBambuserPlayer.VIDEO_SCALE_MODE.ASPECT_FILL}
  resourceUri={BambuserResourceUri}
  onTotalViewerCountUpdate={viewer => {
    this.setState({ views: viewer }); // handle views update here
  }}
  onPlaying={() => {
    // code to handle when playing stream
  }}
  onPlaybackError={error => {
    // handle when some error occures
    Alert.alert('Error', error.message); 
  }}
  onPlaybackComplete={() => {
    // this method called when stream is complete. Write some code to handle stream complete like :
    this.setState({ isPlaying: false, isLiveEnded: true }, () => {
      this.props.navigation.setParams({ isLive: false });
    });
  }}
  onStopped={() => {
    // called when stream stops. 
    this.setState({ isPlaying: false }, () => {
      this.props.navigation.setParams({ isLive: false });
    });
  }}
/>

You can read here more about props.

Glycine answered 28/11, 2019 at 5:25 Comment(15)
Did you use that? I cant stream HD or fullHD quality, It just resize video no capture HDPessa
Yes, I used it. You are right it not properly streaming in HD.Glycine
@VahidAlimohamadi I have made some changes on configuration of nomediaclient and get better quality of streaming. I updated the answer.Glycine
Can I able to live stream using the package alone (rn-video or rn-nomediaclientAubin
Sorry, but I have no idea for that @sejn.Glycine
its not working in ios.. i followed the instruction mentioned in the README file. but not working in ios.Multifarious
Can you provide us the code that you implemented with bambuser in react-native ???Polemist
@KishanBharda I have implemented code! But only audio is audible & video is not visible. I have checked the styling.Polemist
Have you wrapped your <RNBambuserPlayer /> component with <View style={{ flex: 1 }} >...</View> @HelloWorld ?Glycine
Yes I did like this !Polemist
Which value you have set on videoScaleMode ?Glycine
Hey, @KishanBharda is Bambuser a good option for a production app? And where I got the price table for Bambuser or it's free?Homorganic
Yes @OliverD, I think Bambuser is a good option for a production app. bambuser.com/live-streaming-sdk-pricing here you can see all the pricing.Glycine
Cost is highly:0 if we want to go through Free options, what do u suggest?Homorganic
I don't think any library will provide this type of functionality free. If you want to go through free option, you may have to create this functionality library custom using node.js or any other framework.Glycine

© 2022 - 2024 — McMap. All rights reserved.