【问题标题】:Playing music error and relative pathing播放音乐错误和相对路径
【发布时间】:2012-08-02 11:32:43
【问题描述】:

我正在尝试在我的应用程序中播放 mp3,经过大量研究,我仍然无法弄清楚如何进行相对路径,甚至无法使用绝对路径播放音乐。这就是我所拥有的:

//set music
NSError *error;
if (songChosen == 0)
{
    soundPath = @"/Users/aeubanks/Desktop/XCode Stuff/Apps/Game-Storyboard/Game-Storyboard/Amalgamation.mp3";
}
else if (songChosen == 1)
{
    soundPath = @"/Users/aeubanks/Desktop/XCode Stuff/Apps/Game-Storyboard/Game-Storyboard/BUTTERFLY.mp3";
}
audio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundPath] error:&error];
if([[NSFileManager defaultManager] fileExistsAtPath:soundPath] == NO)
{
    NSLog(@"No File");
}

else
{
    NSLog(@"Yes File");
}

if(error != nil)
{
    NSLog(@"%@", error);
}
[audio prepareToPlay];

NSLog 是这样说的(做好准备):

2012-08-04 15:52:02.415 游戏故事板[8430:10703] 是文件

2012-08-04 15:52:02.473 Game-Storyboard[8430:12303] 加载错误 /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen( /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn,262):找不到符号:__CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预计在:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在 /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-04 15:52:02.486 游戏故事板[8430:12303] 加载/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/) 时出错Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn,262):找不到符号:__CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预计在:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在 /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-04 15:52:02.525 游戏故事板[8430:12303] 加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/库/扩展/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):找不到符号:__CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预计在:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在 /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-04 15:52:02.546 Game-Storyboard [8430:12303] 加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/库/扩展/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):找不到符号:__CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预计在:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在 /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-04 15:52:02.570 游戏故事板[8430:12303] 加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/库/扩展/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):找不到符号:__CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预计在:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在 /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-08-04 15:52:02.582 游戏故事板[8430:12303] 加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn: dlopen(/System/) 时出错库/扩展/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):找不到符号:__CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预计在:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在 /System/Library/Frameworks/Security.framework/Versions/A/Security

我也尝试将 soundPath 设置为 @"BUTTERFLY.mp3"/@"Amalgamation.mp3" 以及 @"Game-Storyboard/BUTTERFLY.mp3"/@"Game-Storyboard/Amalgamation.mp3",并且我得到这个:

2012-08-04 15:58:55.763 游戏故事板[8470:10703] 没有文件

2012-08-04 15:58:55.767 Game-Storyboard[8470:10703] 错误域=NSOSStatusErrorDomain Code=-43 “操作无法完成。(OSStatus 错误 -43。)”

我不知道这一切意味着什么,所以我希望能得到一些帮助来解决这个问题。

【问题讨论】:

    标签: ios xcode


    【解决方案1】:

    我会做这样的事情(这里是一个 sn-p):

    if (songChosen == 0)
    {
        NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Amalgamation" ofType:@"mp3"]
        NSURL *soundFileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
        NSError *error;
        AVAudioPlayer *aPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:&error];
    }
    

    我还建议阅读捆绑包。

    【讨论】:

    • 我假设你在模拟器中工作?该错误存在一个已知错误 - 主要问题是声音是否确实播放。
    猜你喜欢
    • 2019-05-06
    • 1970-01-01
    • 2018-02-18
    • 2013-12-25
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多