在 iOS 4.1 中的 iPhone 4 上使用 AVAudioPlayer 播放音频文件时出现问题

发布于 2024-09-25 04:05:29 字数 655 浏览 1 评论 0原文

我正在使用一段简单的代码来播放音频文件:

NSString *pathToMusicFile1 = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"mp3"];
mySong1 = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathToMusicFile1] error:NULL]; 
NSLog(@"Song1 Loaded");
mySong1.numberOfLoops = -1;
mySong1.volume = 1.0;
[mySong1 play];

我导入了 AVFoundation,并在头文件中声明了 mySong1,然后将其合成在我的实现文件中。这段代码在大多数情况下都可以正常工作。我没有收到任何错误,并且音频在模拟器中播放得很好。它在运行 4.0 的 iPhone 3GS 和运行 3.1.3 的原始 iPhone 上也能正常运行。问题是它无法在运行 iOS 4.1 的 iPhone 4 上运行。我尝试过清理项目并重新启动手机。两者都没有帮助。我还尝试了 .aiff 文件而不是 mp3,但也没有运气。

我缺少什么?有没有一种我现在应该使用的播放声音的替代方法?任何帮助表示赞赏。无法弄清楚这里出了什么问题。感谢您的任何帮助。

I am using a simple bit of code to play an audio file:

NSString *pathToMusicFile1 = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"mp3"];
mySong1 = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathToMusicFile1] error:NULL]; 
NSLog(@"Song1 Loaded");
mySong1.numberOfLoops = -1;
mySong1.volume = 1.0;
[mySong1 play];

I have imported AVFoundation and I have declared mySong1 in my header file and then synthesized it in my implementation file. This code works fine, for the most part. I get no errors and the audio plays great in the simulator. It also plays fine on an iPhone 3GS running 4.0 and on an original iPhone running 3.1.3. The problem is that it doesn't play on an iPhone 4 running iOS 4.1. I have tried cleaning the project as well as restarting the phone. Neither helps. I also tried an .aiff file instead of the mp3, but no luck there either.

What am I missing? Is there an alternative way to play sounds that I should be using now? Any help appreciated. Can't figure out what the problem is here. Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巴黎夜雨 2024-10-02 04:05:29

我很尴尬必须发布此内容,但我的手机设置为静音模式 - 这就是为什么我没有从手机上的应用程序收到任何音频。也许我的错误可以帮助别人?希望如此。我花了几个小时才弄清楚这一点。嘎啊!

I’m pretty embarrassed to have to post this, but my phone was set to silent mode - which is why I wasn't getting any audio from my app on my phone. Maybe my mistake helps someone else? Hope so. Just cost me a few hours to figure that out. GAH!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文