Tuesday, 9 July 2019

iOS Library to Play the wav file coming over the socket

I am connecting to a socket which is transmitting audio wav file in 1024 byte chunks and I am looking for a swift library to play that. Just wondering if there is any.

Current state of my code is this.

import UIKit
import SwiftSocket

class ViewController: UIViewController {

let port : UInt32 = UInt32(8190)
let host = "localhost"
let BUFF_SIZE = 1024
let SECRET = "MYSECRET"

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    let client = TCPClient(address: host, port: Int32(port))
    switch client.connect(timeout: 1) {
    case .success:
        switch client.send(data: SECRET.data(using: .utf8) ?? Data() ) {
        case .success:

            var data = [UInt8]()
            while true {
                guard let response = client.read(BUFF_SIZE, timeout: 2) else { break }
                data += response

// I am looking for a library which can play those bytes here.

            }

        case .failure(let error):
            print(error)
        }
    case .failure(let error):
        print(error)
    }

}
}

Thanks



from iOS Library to Play the wav file coming over the socket

No comments:

Post a Comment