LearnVideoToolBox
LearnVideoToolBox copied to clipboard
这段代码用swift怎么写
static OSStatus PlayCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) {
LYPlayer *player = (__bridge LYPlayer *)inRefCon;
ioData->mBuffers[0].mDataByteSize = (UInt32)[player->inputSteam read:ioData->mBuffers[0].mData maxLength:(NSInteger)ioData->mBuffers[0].mDataByteSize];;
NSLog(@"out size: %d", ioData->mBuffers[0].mDataByteSize);
if (ioData->mBuffers[0].mDataByteSize <= 0) {
dispatch_async(dispatch_get_main_queue(), ^{
[player stop];
});
}
return noErr;
}
ioData->mBuffers[0].mDataByteSize = (UInt32)[player->inputSteam read:ioData->mBuffers[0].mData maxLength:(NSInteger)ioData->mBuffers[0].mDataByteSize];;
这一行是核心,用swift写大概是:
ioData.pointee.mBuffers.mDataByteSize = UInt32(player.pointee.inputStream.read(iodata.mBuffers.mData,maxLength: NSInterger(ioData.mBuffers.mDataByteSize)))