@@ -377,6 +377,7 @@ class AudioStreamSourceMicrophone : AudioStreamSourceImpl
377377 int m_frequency ;
378378 string m_deviceName ;
379379 AudioSource m_audioSource ;
380+ GameObject m_audioSourceObj ;
380381 AudioStreamSender m_parent ;
381382
382383 public AudioStreamSourceMicrophone ( AudioStreamSender parent ) : base ( parent )
@@ -414,7 +415,10 @@ IEnumerator CreateTrackCoroutine(WaitForCreateTrack instruction)
414415 // set the latency to “0” samples before the audio starts to play.
415416 yield return new WaitUntil ( ( ) => Microphone . GetPosition ( m_deviceName ) > 0 ) ;
416417
417- m_audioSource = m_parent . gameObject . AddComponent < AudioSource > ( ) ;
418+ m_audioSourceObj = new GameObject ( "Audio" ) ;
419+ m_audioSourceObj . hideFlags = HideFlags . HideInHierarchy ;
420+ DontDestroyOnLoad ( m_audioSourceObj ) ;
421+ m_audioSource = m_audioSourceObj . AddComponent < AudioSource > ( ) ;
418422 m_audioSource . clip = micClip ;
419423 m_audioSource . loop = true ;
420424 m_audioSource . Play ( ) ;
@@ -424,7 +428,7 @@ IEnumerator CreateTrackCoroutine(WaitForCreateTrack instruction)
424428
425429 public override void Dispose ( )
426430 {
427- if ( m_audioSource != null )
431+ if ( m_audioSourceObj != null )
428432 {
429433 m_audioSource . Stop ( ) ;
430434 var clip = m_audioSource . clip ;
@@ -434,7 +438,8 @@ public override void Dispose()
434438 }
435439 m_audioSource . clip = null ;
436440
437- Destroy ( m_audioSource ) ;
441+ Destroy ( m_audioSourceObj ) ;
442+ m_audioSourceObj = null ;
438443 m_audioSource = null ;
439444 }
440445 if ( Microphone . IsRecording ( m_deviceName ) )
0 commit comments