小编Sch*_*eel的帖子

iOS - 从NSFileHandle或NSPipe创建NSURL

我正在通过网络接收编码音频流,但是混合了大量数据,因此我需要接收数据包,删除音频然后播放音频.

AVAudioPlayer,可能是也可能不是最好的工具,但它是我正在追逐的路径,需要来自NSData或NSURL的数据.NSData不起作用,因为它是一个数据流,我希望它一到达就开始继续播放.我的想法是:

NSPipe *pipe = [[NSPipe alloc] init];
NSFileHandle *writeHandle = [pipe fileHandleForWriting];
NSFileHandle *readHandle = [pipe fileHandleForReading];

// in network reception thread...
NSData *audioData = [packet getAudioData];
[writeHandle writeData:audioData];

// in audio thread...
NSURL *url = [[NSURL alloc] init];
[url setResourceValue:NSURLFileResourceTypeNamedPipe 
               forKey:NSURLFileResourceTypeKey 
                error:&error];
// Connect the readHandle
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]
                               initWithContentsOfURL:url
                                               error:&error];
Run Code Online (Sandbox Code Playgroud)

但是,我不知道如何将`readHandle`传递给URL.如何从现有的NSFileHandle创建NSURL?完全有一些更好的方法吗?有没有办法将数据写入可以成为NSURL的东西?

唯一真正的要求是我可以尽可能近乎实时地播放音频.我不希望在播放之前将数据排队甚至十分之一秒.

avaudioplayer ios

8
推荐指数
1
解决办法
1827
查看次数

Enumerate Java Fields

I have a Java class with ~90 fields. I want to be able to do things to every field (generate an XML element for instance) without writing the same 5 lines of code with slight substitutions 90 times. In Objective C I think you can get to instance variables in ways similar to accessing Dictionary elements (ObjectForKey). Is there anything similar in Java such that I can get an array of the fields then do something to each of them?

java

3
推荐指数
1
解决办法
584
查看次数

标签 统计

avaudioplayer ×1

ios ×1

java ×1