Audio Message not working
aiyub007 opened this issue · comments
I am trying to upload media using below code
let messageOptions = TCHMessageOptions()
do {
let inputStream = try InputStream(data: Data(contentsOf: recordingView.getFileURL()))
messageOptions.withMediaStream(inputStream,
contentType: "audio/m4a",
defaultFilename: "sound.m4a",
onStarted: {
},
onProgress: { (bytes) in
}) { (mediaSid) in
self.currentConversationObj.sendMessage(with: messageOptions) { (result, msg) in
if result.resultCode == 200
{
self.currentConversationObj.setAllMessagesReadWithCompletion { (res, count) in }
}
}
I also tried different Mime type [contentType] . Media is there in data control just not going in started or on progress.
completion not working
no error got in the result
Thanks in advance
Hello, you should create options and then send message using these options. To solve your issue it should be enough to move 'sendMessage' from media upload completion.
@Gray-Wind Thanks for response
we are already doing the process for the video it works fine.
As per your suggestion i tries modify it in completed :
let messageOptions = TCHMessageOptions()
do {
let inputStream = try InputStream(data: Data(contentsOf: recordingView.getFileURL()))
messageOptions.withMediaStream(inputStream, contentType: "audio/m4a", defaultFilename: "audio.m4a") {
} onProgress: { (prg) in
print(prg)
} onCompleted: { (mediaSid) in
self.currentConversationObj.sendMessage(with: messageOptions) { (result, msg) in
if result.resultCode == 200
{
self.currentConversationObj.setAllMessagesReadWithCompletion { (res, count) in }
}
}
}
}catch {
print(error as Error)
}
still the same problem.
control is not reaching to the completion not even on progress
Still checking the mime types
It worked
Needed to call out side
{ (mediaSid) in
}
self.currentConversationObj.sendMessage(with: messageOptions) { (result, msg) in
if result.resultCode == 200
{
self.currentConversationObj.setAllMessagesReadWithCompletion { (res, count) in }
}
Basically TCHMessageOptions
doesn't do anything except for telling sendMessage
what to send.
let messageOptions = TCHMessageOptions()
do {
let inputStream = try InputStream(data: Data(contentsOf: recordingView.getFileURL()))
messageOptions.withMediaStream(inputStream,
contentType: "audio/m4a",
defaultFilename: "sound.m4a",
onStarted: {
},
onProgress: { (bytes) in
}) { (mediaSid) in
print("message with sent with sid \(mediaSid)")
}
self.currentConversationObj.sendMessage(with: messageOptions) { (result, msg) in
if result.isSuccessful {
self.currentConversationObj.setAllMessagesReadWithCompletion { (res, count) in }
}
}
}