gpt4 book ai didi

iphone - 如何在 iOS 中列出声音文件?

转载 作者:行者123 更新时间:2023-11-29 11:10:22 24 4
gpt4 key购买 nike

在我的应用程序中,我导入了 4 个声音文件。现在我想在一个 View 中列出所有的声音文件。当用户单击任何一个声音时,需要像在 Alarms 应用程序中一样选择和播放它(选择警报的声音)。这里的区别是我从我的项目中得到声音。我在 SO 和 Google 中进行了搜索,但找不到完全针对此问题的解决方案。

最佳答案

假设“在我的应用程序中我导入了 4 个声音文件”意味着这些文件在您的应用程序包中(并且还假设文件的扩展名是 MP3 - 您可以将其更改为它们实际具有的任何扩展名):

NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSFileManager *mgr = [[NSFileManager alloc] init];

NSArray *allFiles = [mgr contentsOfDirectoryAtPath:bundlePat error:NULL];
for (NSString *fileName in allFiles)
{
if ([[fileName pathExtension] isEqualToString:@"mp3"])
{
NSString *fullFilePath = [bundlePath stringByAppendingPathComponent:fileName];
// fullFilePath now contains the path to your MP3 file
DoSomethingWithFile(fullFilePath);
}
}

关于iphone - 如何在 iOS 中列出声音文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11861072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com