Audio should be play as normal music not as a call

171 views
Skip to first unread message

Sumit Gupta

unread,
Jan 16, 2023, 2:00:09 PM1/16/23
to discuss-webrtc
I'm working on non-calling app so I need to play the audio track as a normal music which I'm not able to do it as webrtc automatically play stream on its own.

I also need to stop/mute the audio because there is an option to pause the streaming in the application as well.

Working on react-native for this. Thanks for replying on this 😊.
It would be very helpful if I get any solution on it.

Florian Grill

unread,
Jan 18, 2023, 7:32:58 AM1/18/23
to discuss-webrtc

Hi,

not sure if react-native works the same way like the native Android/ Java approach but in the java Android API there are two classes you have to adapt

audio\WebRtcAudioTrack.java (change every related STREAM_VOICE_CALL to STREAM_MUSIC)
audio\WebRtcAudioTrack.java  (change every related STREAM_VOICE_CALL to STREAM_MUSIC)

if that doesn't work you might need to compile the lib webrtc youself and change

modules/audio_device/android/opensles_player.cc
sdk/android/src/jni/audio_device/opensles_player.cc

Just search for SL_ANDROID_STREAM_VOICE and change it to SL_ANDROID_STREAM_MEDIA.

Like I said I'm using webrtc in my native Android/ Java app and it works there. Could be that you must do something different for react-native

guest271314

unread,
Jan 18, 2023, 8:00:57 PM1/18/23
to discuss-webrtc
A live MediaStreamTrack cannot be paused.

What you can do is 

- Pass the MediaStream to MediaRecorder then use start(100) and pipe the media chunks from within dataavailable event to SourceBuffer of Media Source Extensions
- Pass the MediaStreamTrack(s) to MediaStreamTrackProcessessor then pass the AudioData and VideoFrame to Media Source Extensions SourceBuffer appendEncodedChunks() 

which will provide a means to pause and resume the playback at HTMLMediaElement.

Florian Grill

unread,
Jan 18, 2023, 8:12:03 PM1/18/23
to discuss-webrtc
In case you just want that the audio will be quite upon the user is pressing a button you can enable and disable the audiotrack. This will work

guest271314

unread,
Jan 18, 2023, 8:19:39 PM1/18/23
to discuss...@googlegroups.com
Disabling and enabling the MediaStreamTrack does not pause the MediaStreamTrack. 

The closest you can get to that using Web API's is using Web Audio API MediaStreamAudioSourceNode, MediaStreamAudioDestinationNode and MediaElementAudioSourceNode with an HTMLMediaElement.

I would pipe the MediaStreamTrack to Media Source Extensions. I have done that successfully using both MediaRecorder and the more recent MediaStreamTrackProcessor with WebCodecs AudioData and VideoFrame, which Media Source Extensions is capable of playing and pausing.

--

---
You received this message because you are subscribed to a topic in the Google Groups "discuss-webrtc" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/discuss-webrtc/Ws_CMkqmV9A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/2e661baf-6bb9-4c1c-a5d2-ce5d2e57bc82n%40googlegroups.com.

Florian Grill

unread,
Jan 25, 2023, 2:40:03 PM1/25/23
to discuss-webrtc
That's why I explicitly mentioned "in case you just want that the audio will be quiet" which is definitely possible by enabling disabling the track but sure it's not a real pause.
Reply all
Reply to author
Forward
0 new messages