Parag Jain
Parag Jain

Reputation: 662

In react-native-webrtc in <RTCView> only video is coming, audio is not working

I am working with react-native-webrtc but I am facing one problem I am able to display video captured by the camera but the audio is not working or we can say I am getting video frames of display and not able to listen any audio. I have given microphone access too and in getusermedia audio and video both parameters are true.

Here is my code:

import React, { Component } from 'react';
import { StyleSheet, View, Button, Text } from 'react-native';
import * as mediasoupClient from 'mediasoup-client';
import {
  RTCPeerConnection,
  RTCIceCandidate,
  RTCSessionDescription,
  RTCView,
  MediaStream,
  MediaStreamTrack,
  mediaDevices,
  registerGlobals,
} from 'react-native-webrtc';
import io from 'socket.io-client/dist/socket.io';
registerGlobals();
class WebRtcScreen extends Component {
  state = {
    MediaStreamx: new MediaStream(),
  };

  componentDidMount() {
    navigator.mediaDevices
      .getUserMedia({ video: true, audio: true })
      .then(this.handleVideo)
      .catch(this.videoError);
  }

  handleVideo = (stream) => {
    this.setState({ MediaStreamx: stream });
  };

  videoError = (err) => {
    console.log(err.name);
  };

  render() {
    return (
      <RTCView
        key={1}
        zOrder={2}
        objectFit="cover"
        style={{ ...styles.rtcView }}
        streamURL={this.state.MediaStreamx.toURL()}
      />
    );
  }
}
const styles = StyleSheet.create({
  rtcView: {
    width: 100, //dimensions.width,
    height: 200, //dimensions.height / 2,
    backgroundColor: 'black',
  },
});

export { WebRtcScreen };

Why is the audio not working here?

Upvotes: 0

Views: 7522

Answers (1)

Anupam Chaplot
Anupam Chaplot

Reputation: 1316

The issue here is that react-native-webrtc plays audio in earphone. You need to use https://github.com/react-native-webrtc/react-native-incall-manager to play audio in phone speaker.

Hope this helps.

Upvotes: 2

Related Questions