此代码播放声音:
NSSound *sound = [[NSSound alloc] initWithContentsOfFile:@"/Users/alex/test.ogg"
byReference:NO];
[sound play];
此代码不会:
NSData *song = [testingResultsData objectAtIndex:0];
[song writeToFile:@"/Users/alex/test.ogg" atomically:YES];
NSSound *sound = [[NSSound alloc] initWithData:song];
[sound play];
两种情况下内容相同;唯一的区别是它是取自磁盘上的文件还是直接取自NSData
.