Expand my Community achievements bar.

changing microphone device while publishing

Avatar

Level 4

i have a common use case where the selected microphone can change during audio publishing. 

however, the newly selected mic doesn't seem to get attached to the currently publishing stream.  calling audioPublisher.stop() and then audioPublisher.publish() once works.  calling it again, after another mic selection, gives the error "Stream cannot be published as it doesnot exists" .

looking into the source of AudioPublisher::publish() , createStream() is only called if _mic == null.  this is a problem for the case i've mentioned above.

is there another way to re-publish() an audio stream after changing the mic (during streaming), or some other approach i should be using?

thanks

adam

3 Replies

Avatar

Former Community Member

Hi Adam,

Indeed, this looks like a bug. Sadly, we're right at the end of a release

cycle, so we can't get this one in for the next release - but we should be

able to help out in a shorter time-frame with a patch. We'll dig into this

and get back to you.

thanks for taking the time to report this - every bit of feedback helps!

nigel

Avatar

Level 4

thanks for the quick confirmation nigel.  while i'm awaiting a patch, i assume the only measure i can take is to make the user choose their microphone before audioPublisher.publish() is called, and not allow them to switch mics after that?

Avatar

Employee

Hi Adam,

There is bug at our end, but you still can change microphone device while publishing. There is some race condition happening which results in an exception that you posted.

So the sequence causing the issue is,

1) You stop mic A's stream

2) You start mic B

3) Mic A is still cached and mic B is not created , resulting in the exception

THe right sequence should be

1) Stop mic A's stream

2) Wait until the client confirms that A is cleaned up

3) Start Mic B.

So listen for StreamEvent.STREAM_DELETE event when you stop a mic, and then publish with the new mic.

I have pasted my sample test code for your reference.

private function init():void
{
        //Security.showSettings();
        audioPub.addEventListener(StreamEvent.STREAM_RECEIVE,onStreamReceive);
        audioPub.addEventListener(StreamEvent.STREAM_DELETE,onStreamDelete);
        //DebugUtil.traceFunction = traceMessage;
}

protected function changeMic(p_evt:MouseEvent):void
{
     audioPub.stop();
     audioPub.microphoneManager.micIndex = Math.floor(Math.random()*3);
     traceMessage("MicIndex" + audioPub.microphoneManager.micIndex);
     _flag =  false;
}

private function onStreamDelete(p_evt:StreamEvent):void
{
        if (!_flag) {
                audioPub.publish();
                _flag = true;
        }
}