ios - 想用 .amr 音频格式文件快速创建一个应用程序
问题描述
您好我想创建一个音频播放器应用程序,其中包含大约 250 首歌曲。应用程序必须离线工作。所以,我尝试使用.aac
和.mp3
格式化音频,但应用程序的大小增加到大约300Mb
.
现在我想使用.amr
格式,但模拟器不适用于该.amr
格式。需要建议。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
playList = [
URL(fileURLWithPath:Bundle.main.path(forResource: "vpn01", ofType: "aac")!),
URL(fileURLWithPath:Bundle.main.path(forResource: "vpn02", ofType: "aac")!),
URL(fileURLWithPath:Bundle.main.path(forResource: "vpn01", ofType: "aac")!),
URL(fileURLWithPath:Bundle.main.path(forResource: "vpn04", ofType: "aac")!),
URL(fileURLWithPath:Bundle.main.path(forResource: "vpn05", ofType: "aac")!),
URL(fileURLWithPath:Bundle.main.path(forResource: "vpn06", ofType: "aac")!),
URL(fileURLWithPath:Bundle.main.path(forResource: "vpn07", ofType: "aac")!)]
解决方案
Check the following points:
不再支持 AMR(对于 ≥ iOS 4.3,请参阅 Apple iOS SDK 文档中支持的音频格式)。您想使用 AVPlayer(音频和视频)还是只需要音频?仅用于音频的 AVAudioPlayer。以下代码片段显示了如何处理它。如果你想使用 AVAudioPlayer,你自己的实例是否实现了 AVAudioPlayerDelegate 协议?您的 self 实例是否实现了 AVAudioPlayerDelegate 协议?您是否添加并正确链接了 AVAudioFoundation 框架(#import)?
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"audio" ofType:@"m4a"]];
NSError *error = noErr;
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (error)
{
NSLog(@"Error in audioPlayer: %@", [error localizedDescription]);
}
else
{
self.audioPlayer.delegate = self;
[self.audioPlayer prepareToPlay];
}
}
- (void)playAudio
{
[self.audioPlayer play];
}
推荐阅读
- prolog - 如何检查列表列表中的所有元素是否相同,除了一个[Prolog]
- php - 为什么 php 不能识别这个查询?
- c# - 连接事件以从部分类的其他文件中运行
- revit-api - 如何在 revit api 中缩放工作表?
- javascript - 通过谷歌云功能打开一个关于松弛的对话框
- java - 如何在 ArrayList 中找到最大值的索引
? - python - 未设置视频模式错误,无法加载图像
- android - 如何在 AsyncTask 中显示 AlertDialog 而不会泄漏上下文?
- javascript - 单击功能更改具有相同类名的所有元素
- javascript - 根据操作系统在 Gulp 中运行不同的可执行字符串