Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio input is gone if input is stopped once #75

Open
pilzinho opened this issue Jan 15, 2024 · 1 comment
Open

Audio input is gone if input is stopped once #75

pilzinho opened this issue Jan 15, 2024 · 1 comment

Comments

@pilzinho
Copy link

When stopping an input calling DeckLinkInput.StopInput(), the AudioClip of the AudioSource is destroyed. So when starting the input again by calling Begin() the audio will not start again.

We solved this for now in DeckLinkInput by destroying the whole AudioSource when stopping and moving the creation of the AudioSource from the Awake() to the Begin() method like so:

protected override void BeginDevice()
{
        ...
        
	if (_device != null)
	{
		_enable3D = _device.Enable3DInput;
		_device.FlipInputX = _flipX;
		_device.FlipInputY = _flipY;
		InitAudio();
		DeckLinkPlugin.FlushAudioBuffer(_deviceIndex);
	}
}

private void InitAudio()
{
	if (_audioSource)
		StopAudio();
	
	_audioSource = gameObject.AddComponent<AudioSource>();
	_audioSource.hideFlags = HideFlags.HideInInspector;
	_audioSource.loop = true;
}
		 
private void StopAudio()
{
	if (!_audioSource)
		return;
	
	_audioSource.Stop();
	if (_audioSource.clip != null)
	{
		AudioClip.Destroy(_audioSource.clip);
		_audioSource.clip = null;
	}
	Destroy(_audioSource);
}

StopAudio() is called by the StopInput() and Cleanup() methods.

Copy link

stale bot commented Mar 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale label Mar 17, 2024
@RichRH RichRH removed the stale Stale label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants