gpt4 book ai didi

ios - 如何使用 AVAudioPlayer 播放 .m4a 歌曲文件?

转载 作者:行者123 更新时间:2023-12-03 13:21:03 26 4
gpt4 key购买 nike

我在下载这首歌的同时尝试从 iTunes 商店播放它

为什么下面的代码不能播放?

NSLog(@"start");

NSURL *songUrl = [NSURL URLWithString:@"http://a1804.phobos.apple.com/us/r1000/064/Music/v4/9b/b3/c7/9bb3c7dc-a06f-f18c-3e41-2ce1e36f73b4/mzaf_7432104896053262141.aac.m4a"];


NSError* errorVar = nil;
AVAudioPlayer* song = [[AVAudioPlayer alloc] initWithContentsOfURL:songUrl error:&errorVar];
[song prepareToPlay];
[song play];

最佳答案

我认为你必须使用 AVPlayer 而不是 AVAudioPlayer。

Apple 文档建议使用 AVAudioPlayer 播放文件或内存中的音频数据。 AVPlayer 适用于本地和远程媒体文件。

self.player = [AVPlayer playerWithURL:<#Live stream URL#>];
[player addObserver:self forKeyPath:@"status" options:0 context:&PlayerStatusContext];

引用Apple Docs了解更多信息。

关于ios - 如何使用 AVAudioPlayer 播放 .m4a 歌曲文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17006002/

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