如何在 Xcode 4.2 的 Mac 应用程序中播放 mp3

发布于 2024-12-28 22:04:45 字数 49 浏览 2 评论 0原文

我正在尝试在 Xcode 4.2 中的 Mac 应用程序中播放 mp3。我该怎么做?

I'm trying to play an mp3 in a Mac Application in Xcode 4.2. How would I do this?

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

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

发布评论

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

评论(2

笑,眼淚并存 2025-01-04 22:04:45

您没有给我们太多的帮助...

如果您只想要简单的声音,请使用 NSSound

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"fn" ofType:@"mp3"];
NSSound *sound = [[NSSound alloc] initWithContentsOfFile:resourcePath byReference:YES];
[sound play];
// wait for the sound to play before you release these...

使用 NSSound,声音会与您的代码同时播放。一个常见的错误是在声音或资源仍在播放时释放它。不要那样做。

您还可以使用 QTMovie in QTKit

NSError *err = nil;
QTMovie *sound = [[QTMovie movieWithFile:@"fn.mp3" error:&err] retain];
[sound play];

对于要求更高的声音,请使用 <一个href="http://developer.apple.com/library/mac/#documentation/MusicAudio/Conceptual/CoreAudioOverview/Introduction/Introduction.html" rel="nofollow noreferrer">CoreAudio

You are not giving us much to work with...

If you just want a simple sound, use NSSound:

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"fn" ofType:@"mp3"];
NSSound *sound = [[NSSound alloc] initWithContentsOfFile:resourcePath byReference:YES];
[sound play];
// wait for the sound to play before you release these...

With NSSound, the sound plays concurrently with your code. A common mistake is to release the sound or resource while it is still playing. Don't do that.

You can also use QTMovie in QTKit:

NSError *err = nil;
QTMovie *sound = [[QTMovie movieWithFile:@"fn.mp3" error:&err] retain];
[sound play];

For more demanding sounds, use CoreAudio

就像说晚安 2025-01-04 22:04:45

您应该使用 QTKit 框架和 QTMovie 类。

You should use QTKit framework and the QTMovie class.

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