SoundManager加载来自不同文件夹的声音

时间:2014-02-28 23:12:23

标签: objective-c directory

我一直在Objective C中工作,我使用SoundManager加载我的音乐/声音,但现在我尝试从不同的文件夹(MyXcodeProjectFolder / Soundboard / whatever.mp3 /)加载一些声音,但SoundManager总是说该文件不存在,有人对我这么棒吗?我尝试了很多,但每次他都找不到它,或者他根本就没玩过。

这里写了一些代码:

Inside my ViewController.h
[soundLoader playSound:@"~/Soundboard/letitgoremix.mp3"];


Inside the soundLoader (Not mine, just made an object for playing sound faster)

+(void)playSound: (NSString *)song
{
    [SoundManager sharedManager].allowsBackgroundMusic = YES;
    [[SoundManager sharedManager] prepareToPlay];

    if ([SoundManager sharedManager].playingMusic)
    {
        [[SoundManager sharedManager] stopMusic: true];
    }

    [[SoundManager sharedManager] playMusic:song looping:NO];
}

对于SoundManager源,您可以在这里查看:https://github.com/nicklockwood/SoundManager

这也是我第一次使用Xcode和Objective-c进行编码,所以如果我的语法不正确,我很抱歉。

感谢您的阅读,我希望有人能帮我解决问题。

修改

我发现了问题,我的音乐文件夹没有在Xcode中正确添加,而且没有在.app中使其成为正确的副本。

1 个答案:

答案 0 :(得分:1)

要解决我的问题,我需要做两件事:

  1. 将音乐文件夹设置为参考,而不是组。

  2. 我使用此代码将声音/音乐加载到文件夹中。

  3. 代码:只需更改“MusicFileNameHere”和“Folder / Location / here”。

    NSString *music = [[NSBundle mainBundle] pathForResource:@"MusicFileNameHere" ofType:@"mp3" inDirectory:@"Folder/Location/Here"];
    

    希望能帮助与我有同样问题的人!

相关问题