簡體   English   中英

在iOS中瀏覽內置聲音

[英]Browsing built-in sounds in iOS

是否有API(或只是一種hack)來用iOS設備上的內置聲音名稱填充TableView? 例如,查看Clock應用程序的警報部分:您可以從聲音名稱的TableView中為警報選擇聲音。

對於越獄電話,您可以訪問文件系統並獲取文件列表。

-(void)loadAudioFileList{
    audioFileList = [[NSMutableArray alloc] init];

    NSFileManager *fileManager = [[NSFileManager alloc] init];
    NSURL *directoryURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds"];
    NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey];

    NSDirectoryEnumerator *enumerator = [fileManager
                                         enumeratorAtURL:directoryURL
                                         includingPropertiesForKeys:keys
                                         options:0
                                         errorHandler:^(NSURL *url, NSError *error) {
                                             // Handle the error.
                                             // Return YES if the enumeration should continue after the error.
                                             return YES;
                                         }];

    for (NSURL *url in enumerator) {
        NSError *error;
        NSNumber *isDirectory = nil;
        if (! [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) {
            // handle error
        }
        else if (! [isDirectory boolValue]) {
            [audioFileList addObject:url];
        }
    }
}

來自庫的GitHub存儲庫。 iOSSystemSoundsLibrary

  • iOS中使用的所有系統聲音的列表
  • 在iOS設備上運行項目以測試所有可用的系統聲音
  • iOS Simulator無法播放系統聲音

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM