Spotify in Unity

So I’m working on a game where music is a big factor. And rn I’ve imported some own music but how cool would it be if I my game can react to the music that is playing in the background (like spotify and youtube music).

Is there something like device.audio or anything else that would turn the device audio into a audio source?

Some gameplay (particles react to music)

i assume device.audio or anything else will turn the device audio into an audio source in my opinion it is correct

I’m just trying to do the same and have found a solution.

void UpdateMic()
    {
        if (currentIndex != inputIndex)
        {
            currentIndex = inputIndex;
            //micClip?.UnloadAudioData();
            if (currentIndex < 0)
            {
                //micClip = null;
                if (audioSrc != null)
                {
                    audioSrc.Stop();
                }
            }
            else
            {
                if (audioSrc == null)
                    audioSrc = GetComponent<AudioSource>();
                if (audioSrc == null)
                    audioSrc = gameObject.AddComponent<AudioSource>();

                string activeDevice = Microphone.devices[currentIndex % Microphone.devices.Length];
                audioSrc.clip = Microphone.Start(activeDevice, true, 1, 44100);

                int micPos, k = 0;
                //this supposedly reduces lag
                do
                {
                    micPos = Microphone.GetPosition(activeDevice);
                } while (!(micPos > 0) && k++<100000);
                Debug.Log("MIC POS " + micPos + " (" + k + ")");

                audioSrc.loop = true;
                audioSrc.Play();
                audioSrc.outputAudioMixerGroup = mixer;
            }
        }
    }

My main problem then was that audio playing in the background is not in synch with what Unity is playing. Slight delay. This took me quite a while to figure out, but I found Virtual Audio Cable - Downloads (Virtual Audio Cable). If you send Audio from Spotify to Line1 (virtual device) and read/play from this device in Unity you can have everything in sync.

just found out how to do this about 10min ago, but the audio-quality is reduced and I don’t know why yet. maybe you can help me figure this out.

If you really would like to get this feature, I suggest you submit your idea on our roadmap. It is the best way to request and see what we are planning and doing. https://unity.com/roadmap/unity-platform/audio-video. :slight_smile:

Yes, it is possible to make your game react to the music playing in the background. You can achieve this through audio visualization, which is a technique used to display the elements of sound in a visual manner.