I am using AVAudioPlayer to play recorded audio which is saved in Iphone's Document directory. When I first record an audio and then play, it works fine (Device is connected to the system and App is running through Xcode).
But when I Stop the running App through Xcode and again run the App through Xcode, I am getting Error Error Domain=NSOSStatusErrorDomain Code=2003334207 "The operation couldn’t be completed. (OSStatus error 2003334207.)"
File Location: file:///var/mobile/Containers/Data/Application/410AB24E-5FB0-4401-AC59-3C03D676E951/Documents/26-06-2015--13:10:47.m4a
My Code:
fileLocation = @"file:///var/mobile/Containers/Data/Application/410AB24E-5FB0-4401-AC59-3C03D676E951/Documents/26-06-2015--13:10:47.m4a"
NSURL *fileUrl = [NSURL URLWithString:fileLocation];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileUrl error:&error];
[player setDelegate:self];
NSURL *fileUrl = [NSURL URLWithString:fileName];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileUrl error:&error];
[player setDelegate:self];
I am using Xcode 6 and running App in IOS 8
P.S: I have read so many documentations related to this issue and also several questions in statckoverflow itself, but I didn't find the answer.
Under iOS8, the path that you have saved won't be valid across launches. The id you see "410AB24E-5FB0-4401-AC59-3C03D676E951" will change with each launch.
The solution is to save the filename and not the complete path, and to recreate the URL or complete path, by getting the path to the Documents (or tmp) folder and appending the filename to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With