قالب وردپرس درنا توس
Home / IOS Development / ios – Play audio from CMSampleBuffer

ios – Play audio from CMSampleBuffer



I've created a video chat app for groups in iOS. I have searched for some ways to control the sound volume of different participants separately. I found the way to mute unmute using isPlaybackEnabled in RemoteAudioTrack but not to control the volume.

I also thought we could use it in AVAudioPlayer . I found addSink . This is what I tried from here

  class sound: NSObject, AudioSink {
was a = 1
func renderSample (_ audioSample: CMSampleBuffer!) {
print ("sound found", a)
a + = 1

was audioBufferList = AudioBufferList ()
var data = Data ()
was blockBuffer: CMBlockBuffer?

CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer (audioSample, bufferListSizeNeededOut: nil, bufferListOut: & audioBufferList, bufferListSize: MemoryLayout . Size, blockBufferAllocator block: zero, zero:
let buffers = UnsafeBufferPointer  (start: & audioBufferList.mBuffers, count: Int (audioBufferList.mNumberBuffers))

for audio buffer in buffers {
la ramme = audioBuffer.mData? .assumingMemoryBound (for: UInt8.self)
data.append (frame !, count: Int (audioBuffer.mDataByteSize))
}

let player = try! AVAudioPlayer (data: data) // crashes here
player.play ()
}
}

But It crashed on let player = try! AVAudioPlayer (data: data) .


Source link