Swift Audio Not Playing On Device

I have some swift code here.

//
//  ContentView.swift
//  Shared
//
//  Created by Ulto4 on 10/23/21.
//

import SwiftUI
import AVFoundation

struct ContentView: View {
    
    var body: some View {
        VStack{
        
        Button(action : {
            self.fu()
        }, label: {
            Image("logo1").resizable().aspectRatio(contentMode:.fit)
        })
          
        }
    }
    func fu(){
    
        //let randomCode = Int.random(in: 0...5000)
        //let randomString = randomCode.description
        let randomString = "575"
   
        let session = URLSession.shared
        let url = URL(string: "http://***.*.*.*:5000/\(randomString)")!
        let task = session.dataTask(with: url, completionHandler: { data, response, error in
            // Check the response
                    print(error)
                    print(response)
            })
            task.resume()
        sleep(10)
        let url2 = URL(string: "http://***.*.*.*:5000/\(randomString).wav")!
        let downloadTask = URLSession.shared.downloadTask(with: url2) {
            urlOrNil, responseOrNil, errorOrNil in
            // check for and handle errors:
            // * errorOrNil should be nil
            // * responseOrNil should be an HTTPURLResponse with statusCode in 200..<299
            
            guard let fileURL = urlOrNil else { return }
            do {
                let documentsURL = try
                    FileManager.default.url(for: .documentDirectory,
                                            in: .userDomainMask,
                                            appropriateFor: nil,
                                            create: false)
                let savedURL = documentsURL.appendingPathComponent(fileURL.lastPathComponent)
                
                try FileManager.default.moveItem(at: fileURL, to: savedURL)
                self.play(url: savedURL)
            } catch {
                print ("file error: \(error)")
            }
           
        }
        
        downloadTask.resume()
        print("cool")
        
        }
    func play(url:URL) {
        print("playing \(url)")
        //guard let url3 = Bundle.main.url(forResource: url.description, withExtension: "wav") else { return print("bruh")}\
        
        
        
        do {
            var player = try! AVAudioPlayer(contentsOf: url)
            player.prepareToPlay()
            player.volume = 5.0
            player.play()
            print("IT WORKED?!?!?!?!?!")
        } catch let error as NSError {
            //self.player = nil
            print(error.localizedDescription)
            print("no")
        } catch {
            print("AVAudioPlayer init failed")
        }
        
    }
    func play2(url:String){
        var player: AVAudioPlayer!
                    
            let url2 = Bundle.main.url(forResource: url, withExtension: "wav")
             
            player = try! AVAudioPlayer(contentsOf: url2!)
            player.play()
        
    }
    
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView().preferredColorScheme(.dark)
    }
   
        
    }




When I ran it on a simulator it said something about and Audio Plugin, and so I ran it on my phone. However, the console doesn't print "It's Working" or anything for that matter. I don't really know if it's the audio or something else. The requests are working because my server's log shows it . What am I doing wrong here. I am new to swift so any help would be highly appreciated.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum