好的.我正在寻找一种简洁的方法来列出用[NSSound soundnamed:]播放的系统声音 – 对我而言似乎API没有可用声音列表.
我还用谷歌搜索了这个,发现了一些相当旧的,部分已被弃用的来源.如果应用程序应该有一个声音拾取器 – 什么是获得系统提供的声音列表的最佳方法?
解决方法 这是我的实施.NSSound(systemSounds.h):
#import <AppKit/AppKit.h>@interface NSSound (systemSounds)+ (NSArray *) systemSounds;@end
NSSound(systemSounds.m):
#import "NSSound (systemSounds).h"@implementation NSSound (systemSounds)static NSArray *systemSounds = nil;+ (NSArray *) systemSounds{ if ( !systemSounds ) { NSMutableArray *returnArr = [[NSMutableArray alloc] init]; NSEnumerator *librarySources = [NSSearchPathForDirectorIEsInDomains(NSlibraryDirectory,NSAllDomainsMask,YES) objectEnumerator]; Nsstring *sourcePath; while ( sourcePath = [librarySources nextObject] ) { NSEnumerator *soundSource = [[NSfileManager defaultManager] enumeratorAtPath: [sourcePath stringByAppendingPathComponent: @"Sounds"]]; Nsstring *soundfile; while ( soundfile = [soundSource nextObject] ) if ( [NSSound soundnamed: [soundfile stringByDeletingPathExtension]] ) [returnArr addobject: [soundfile stringByDeletingPathExtension]]; } systemSounds = [[NSArray alloc] initWithArray: [returnArr sortedArrayUsingSelector:@selector(compare:)]]; [returnArr release]; } return systemSounds;}@end
可自由使用,可供任何人用于任何目的,如果你增强它,请分享:)
总结以上是内存溢出为你收集整理的xcode – 声音选择器/系统声音列表全部内容,希望文章能够帮你解决xcode – 声音选择器/系统声音列表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)