LearnVideoToolBox icon indicating copy to clipboard operation
LearnVideoToolBox copied to clipboard

这段代码用swift怎么写

Open MasterMusketeer opened this issue 6 years ago • 1 comments

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;

}

MasterMusketeer avatar Nov 16 '18 09:11 MasterMusketeer

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)))

SuperKenVery avatar Jan 28 '21 09:01 SuperKenVery