I want to make iOS
device as source client to send the audio to icecast
server. I have setup the icecast
server on localhost
successfully. Right now when I send below request to server it creates the mountpoint
but only for first 8 sec
of the audio
, the total length of audio
is 25 sec
. I know this is because I'm not sending the data in chunks. Below is my request:
let requestString = "http://localhost:8000/"
let url = URL(string: requestString)
let mountPointName = "myMountPoint"
var request = URLRequest(url: url!)
request.httpMethod = "SOURCE /\(mountPointName) ICE/1.0"
request.addValue("SOURCE /mp3test ICE/1.0", forHTTPHeaderField: "SOURCE")
request.addValue("audio/ogg", forHTTPHeaderField: "Content-Type")
request.setValue("Basic c291cmNlOmhhY2ttZQ==", forHTTPHeaderField: "Authorization")
request.setValue("Server name", forHTTPHeaderField: "ice-name")
request.setValue("https://www.google.com", forHTTPHeaderField: "ice-url")
request.setValue("RockTest", forHTTPHeaderField: "ice-genre")
request.setValue("128", forHTTPHeaderField: "ice-bitrate")
request.setValue("0", forHTTPHeaderField: "ice-private")
request.setValue("1", forHTTPHeaderField: "ice-public")
request.setValue("Server description", forHTTPHeaderField: "ice-description")
request.setValue("samplerate=44100;bitrate=128;channels=2", forHTTPHeaderField: "ice-audio-info")
self.recurseivelySendRequest(request)
My recursive function:
func recurseivelySendRequest(_ _request: URLRequest) {
var request = _request
do {
let fileURL = Bundle.main.url(forResource: "mount", withExtension: "ogg") let data = try Data(contentsOf: fileURL!)
let inputStream = InputStream(data: data)
request.httpBodyStream = inputStream
} catch let error {
print(error)
}
// let dataTask = URLSession.shared.uploadTask(withStreamedRequest: request)
// dataTask.resume()
let dataTask = URLSession.shared.dataTask(with: request) { (data, response, error) in
if (error != nil) {
print(error ?? "error = unknown")
return
}
print(response ?? "response = unknown")
do {
let json = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers)
print(json)
} catch let error {
print(error)
let str = String.init(data: data!, encoding: String.Encoding.utf8)
print(str ?? "str = nil")
}
self.recurseivelySendRequest(request)
}
dataTask.resume()
}
The problem with above code is it sends only few part of the audio
also If I don't send the request recursively the mountpoint
no longer exists and seems it is replacing the data not adding. So what I want is to create the mountpoint
once and then write the audio data in chunks.
I also followed Icecast 2: protocol description, streaming to it using