复制音频到一般UIPasteboard



我正在使用通用UIPasteboard在我的音频合成应用程序中实现音频复制功能,以便复制的音频可以粘贴在MAPI: AudioCopy/AudioPasteIntua Audio Sharing启用的应用程序中。在这个过程中似乎有一个问题,复制的音频没有出现在AudioPaste启用的应用程序中。

这就是我所做的复制音频到一般的UIPasteboard。

NSData *newItemData = [NSData dataWithContentsOfFile:[dataPath stringByAppendingPathComponent:@"converted.wav"]];      

// This is the copy operation using the General Pasteboard otherwise known as the Intua Pasteboard
UIPasteboard *board = [UIPasteboard generalPasteboard];
[board setPersistent:TRUE];
NSData *dataFile = newItemData;
if (!dataFile) {
    NSLog(@"Can't open file");
}
// Create chunked data and append to clipboard
NSUInteger sz = [dataFile length];
NSUInteger chunkNumbers = (sz / GP_CLIPBOARD_CHUNK_SIZE) + 1;
NSMutableArray *items = [NSMutableArray arrayWithCapacity:chunkNumbers];
NSRange curRange;
for (NSUInteger i = 0; i < chunkNumbers; i++) {
    curRange.location = i * GP_CLIPBOARD_CHUNK_SIZE;
    curRange.length = MIN(GP_CLIPBOARD_CHUNK_SIZE, sz - curRange.location);
    NSData *subData = [dataFile subdataWithRange:curRange];
    NSDictionary *dict = [NSDictionary dictionaryWithObject:subData forKey:(NSString *)kUTTypeAudio];
    [items addObject:dict];
}
board.items = items;

执行此步骤后,当我启动AudioPaste兼容应用程序时,我看不到刚刚复制的音频。你能在我的音频复制代码中发现任何错误吗?

我不相信您通过添加" transformed .wav"创建的路径存在。在继续复制之前,我会检查文件路径是否存在。你可能会发现路径看起来像"myaudifile .wavconverted.wav"。

作为一个小提示,由[UIPasteboard generalPasteboard]返回的General Pasteboard总是持久的,所以你不需要将它设置为persistent。

最新更新