MetalAudioVisualizer icon indicating copy to clipboard operation
MetalAudioVisualizer copied to clipboard

Only outputs sounds/visuals when application is hidden from view

Open mcstrassell09 opened this issue 3 years ago • 1 comments

I followed the tutorial word for word. The program builds without an issue in Xcode. However running the app results in weird behavior. The app will only function correctly if hidden from view i.e. if the app is minimized or if I am in another app that is in fullscreen. When I switch to view the audiovisualizer the both the audio and visuals stop over a period of seconds. Then if I re-minimize the audiovisualizer or move to another app in full screen, the program will output again normally.

I got some warnings in Xcode about CAMetalLayer returning nil because allocation failed. Its just really strange to me. Running on a 2018 MBP with Intel Core I9, Intel UHD graphics 630 & AMD Radeon 555x with dynamic graphics switching. I'm new to Metal and super duper frustrated. Thanks for your help!

Screen Shot 2022-02-17 at 4 40 20 PM Screen Shot 2022-02-17 at 10 36 02 AM

mcstrassell09 avatar Feb 17 '22 21:02 mcstrassell09

Update AudioVisualizer.swift:

Replace all of the metalView.draw() by

DispatchQueue.main.async() { [self] in
    metalView.updateLayer()
}

And change metalView.isPaused = true to metalView.isPaused = false

Daniate avatar Jul 24 '22 10:07 Daniate