Can't publish a stream with audio only

Hello,

I’m not sure if this is a common issue but for some reason I am unable to publish a stream with only audio. The only time audio works is if the video is also active.

I wish to give control to users to choose whether to publish video only, audio only, or both. Users have a camera icon they press to publish the video and microphone icon they press to publish the audio. When they first click either the video or audio icon the stream is initially published; afterwards, when they press an icon, either the tablePublisher.publishVideo(bool) or tablePublisher.publishAudio(bool) is executed. As described through, the audio is only active when the video is active. It doesn’t seem possible to have only the audio active without video. Any help would be really appreciated! My code is seen below:

changeMuteState = () => {
let {tablePublisher} = this.props.eventData;
if (this.props.eventData.isMuted){
if (tablePublisher === undefined){
this.initialStreamPublish(true, false);
this.props.muteSelf(false);
}
else{
tablePublisher.publishAudio(true);
this.props.muteSelf(false);
}
}
else{
tablePublisher.publishAudio(false)
this.props.muteSelf(true);
}
}

publishSelf = () => {
  let {tablePublisher} = this.props.eventData;
  if (tablePublisher === undefined){
    this.initialStreamPublish(false, true);
    this.props.updateVisibility(true);
    this.props.muteSelf(false);
  }
  else{
    //tableSession.publish(tablePublisher);
    tablePublisher.publishVideo(true);
    this.props.updateVisibility(true);
  }
}

unpublishSelf = () => {
  let { tablePublisher } = this.props.eventData;
  if (tablePublisher && tablePublisher.stream){
    //tableSession.unpublish(tablePublisher);
    tablePublisher.publishVideo(false);
    this.props.updateVisibility(false);
  }
}


initialStreamPublish = (audioOption, videoOption) => {
  let {tableSession, tableConnectionId} = this.props.eventData;
  if (tableSession !== undefined || tableConnectionId === ''){
    let tablePublisher = this.props.OV.initPublisher(undefined, {
      audioSource: undefined, // The source of audio. If undefined default microphone
      videoSource: undefined, // The source of video. If undefined default webcam
      publishAudio: audioOption, // Whether you want to start publishing with your audio unmuted or not
      publishVideo: videoOption, // Whether you want to start publishing with your video enabled or not
      resolution: '320x240', // The resolution of your video
      frameRate: 30, // The frame rate of your video
      insertMode: 'APPEND', // How the video is inserted in the target element 'video-container'
      mirror: true, // Whether to mirror your local video or not
    });
    // --- 6) Publish your stream ---
    tableSession.publish(tablePublisher);
    // Set the main video in the page to display our webcam and store our Publisher
    this.props.setTablePublisher(tablePublisher);
  }
}

hello
i use openvidu android
i also need video enabled for sound to work

Hello,

Audio only streams are of course supported in OpenVidu. For example: OpenVidu Call application allows publishing audio-only streams: https://demos.openvidu.io/openvidu-call/. You can also enable/disable audio and/or video at any time in that demo application. Is something similar to that what you want to achieve?

I’m sure this is just a problem of your frontend implementation. I don’t know if the code you posted is buggy, but you just have to take into account 2 things:

  1. When starting your Publisher object, you must provide a valid audioSource and videoSource if you want that user to be able to stream both audio and video: https://docs.openvidu.io/en/latest/cheatsheet/publish-unpublish/. If you don’t want to publish audio or video ever, then initialize them to false.

  2. For an active Publisher, you can temporarely disable its audio or video stream by calling publishAudio and publishVideo methods: https://docs.openvidu.io/en/latest/cheatsheet/mute-audio-video/. Of course to do so, you must have initialized the Publisher object with valid audioSource and videoSource properties.

Maybe there is a problem with your HTML video element management. I recommend that you take a look at this section of the documentation to make sure you understand it: https://docs.openvidu.io/en/latest/cheatsheet/manage-videos/.

Regards.