         }
     }
 
+    public var isPrepared: Bool {
+        true
+    }
+    
     //Audio Units
     private let timePitch: AVAudioUnitTimePitch = AVAudioUnitTimePitch()
     private let equalizer: AVAudioUnitEQ = AVAudioUnitEQ(numberOfBands: kNumberOfBands)

        delegate?.playbackStopped(trackCompleted: false)
    }
    
    private func setupPlayer() {
        guard let id = mediaItem?.playbackStoreID else {
            return
        }
        
        // This API is apparently very sensitive to order of operation.
        // The below is the only sequence that appears to operate consistently and reliably
        // for this use case as of iOS 14.4.
        // Variations of this order have introduced significant (3-5 second) delays
        // and blocking of the main thread when invoking prepareToPlay()
        //
        // Noli Se Tangere

        MusicPlayer.player.setQueue(with: [id])
        MusicPlayer.player.currentPlaybackTime = .zero
        MusicPlayer.player.repeatMode = .none
        MusicPlayer.player.shuffleMode = .off
        MusicPlayer.player.prepareToPlay()
    }
    
    @objc private func handleStateChange(notification: Notification) {

/// after initialization to see what is available.
public struct AudioPlayerFactory {
    ///Create an appropriate audio player based on the media item
    public static func createPlayer(for mediaItem: MPMediaItem, _ completion: @escaping (AudioPlayer)->Swift.Void) {
        if mediaItem.assetURL != nil {
            completion(FXAudioPlayerEngine(mediaItem: mediaItem))
        }
        else {
            let player = MusicPlayer(mediaItem: mediaItem)
            player.setupPlayer {
                completion(player)
            }
        }
    }
    
    public static func createPlayer(for asset: AVURLAsset, _ completion: @escaping (AudioPlayer)->Swift.Void) {
        completion(FXAudioPlayerEngine(asset: asset))
    }
}

