0

In my app, one can record and save songs. Upon updating my app, I get an error trying to initialize an AVAudioPlayer. The song is saved in the documents directory, and I simply create a URL to the documents directory with that song and get the error above. When reading other answers to similar questions, it says that -43 is a file not found error, so I outputted everything in my documents directory, and I can clearly see that the file I'm trying to access is in the documents directory. It cannot be an error in the path to the documents directory as I simply use

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

to get the documents directory.

How I initialize the audioplayer, the error and URL I'm trying to access:

[[AVAudioPlayer alloc]initWithContentsOfURL:urlOfSong error:&error]; 
if (error)
        {
            NSLog(@"Error in audioPlayer: %@", 
                  [error localizedDescription]);
            NSLog(@"error with this: %@",urlOfSong);
        }


2013-01-24 18:51:40.223 app[14104:907] Error in audioPlayer: The operation couldn’t be completed. (OSStatus error -43.)
2013-01-24 18:51:40.224 app[14104:907] error with this: file://localhost/var/mobile/Applications/C8F1FB54-CF7E-46EC-9B87-8BE3CE9B0A3D/Documents/k%20-%20Spongebob.m4a

Which can be seen that the file I'm trying to play is called k - Spongebob.m4a

Here is the output of my documents directory:

2013-01-24 18:51:40.228 app[14104:907] (
    "Recording 11413, 10:28 PM - All I Need.m4a",
    "k - Spongebob.m4a" 
)

Keep in mind that I mentioned that this was only AFTER I updated my app. When testing before sending out the update, everything worked perfectly. And if I record a new song and save it and then try to play it using the exact same methods, it works just fine. This is happening when I'm trying to play a song that I recorded before the update.

Any help guys???

4

1 回答 1

2

我想到了。显然,当您更新应用程序时,路径中文档前面的字母和数字(即 0B6DDD37-792B-4C1A-98A3-1A96B64B4DB0)会发生变化。我用旧字母和数字保存旧路径并尝试使用该路径进行初始化,这就是错误发生的原因。我只需要使用文档目录的当前路径进行初始化。这解释了为什么在发送更新之前进行测试时没有发生此错误。

于 2013-01-25T00:56:28.007 回答