播放音乐错误和相对路径

时间:2012-08-04 22:02:21

标签: ios xcode

我试图在我的应用程序中播放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 Game-Storyboard [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 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.525 Game-Storyboard [8430:12303]加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen(/ System / Library / Extensions / 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 / Library / Extensions / 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 Game-Storyboard [8430:12303]加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen(/ System / Library / Extensions / 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 Game-Storyboard [8430:12303]加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen(/ System / Library / Extensions / 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    in /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 Game-Storyboard [8470:10703]没有文件

     

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

我不知道这一切意味着什么,所以我很感激帮助解决这个问题。

1 个答案:

答案 0 :(得分:0)

我会做这样的事情(这是一个片段):

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];
}

我还建议阅读捆绑包。