     
     deinit {
         NotificationCenter.default.removeObserver(self)
-    }
-    
+        engine.stop()
+    }
+    
+   #if os(iOS) || os(watchOS)
     ///Call this is to setup playback options for your app to allow simulataneous playback with other apps.
     /// The default mode allows playback of audio when the ringer (mute) switch is enabled.
     /// Be sure to enable audio in the BackgroundModes settings of your apps Capabilities if necessary.
-    #if os(iOS) || os(watchOS)
-    public class func initAudioSessionCooperativePlayback(category: AVAudioSession.Category = .playback,
+     public class func initAudioSessionCooperativePlayback(category: AVAudioSession.Category = .playback,
                                                           policy: AVAudioSession.RouteSharingPolicy = .longFormAudio) {
         do {
             try AVAudioSession.sharedInstance().setActive(false)

        engine.attach(routingMixer)
        
        //construct fx node graph... connect to output of the playback mixer
        engine.connect(player, to: timePitch, format: nil)
        engine.connect(timePitch, to: equalizer, format: nil)
        engine.connect(equalizer, to: routingMixer, format: nil)
        engine.connect(routingMixer, to: engine.mainMixerNode, format: nil)

    //AVAudioEngine and nodes
    internal var engine: AVAudioEngine = AVAudioEngine()
    internal var player: AVAudioPlayerNode = AVAudioPlayerNode()
    internal let mixer: AVAudioMixerNode = AVAudioMixerNode()

    //audio file
    internal var audioFile: AVAudioFile?
    
