xcode - iOS - Reading an Audio file from Documents Directory -


i saving audio data documents directory , trying read back. if play plays successfully, however, if start new session , try , play song locally fail though listing files in documents directory shows file still there. note file played documents folder in same way (same code) if played or during new session.

here how save audio data documents directory:

+(void)writedatatoaudiofile:(nsdata*)data fortrack:(mediaitem*)track {     // filename looks "[track_id].mp3"      nsstring *filename = [nsstring stringwithformat:@"%@.%@",track.sc_id,track.original_format];      nsstring *pathname = [[nssearchpathfordirectoriesindomains(nsdocumentdirectory,                                                                   nsuserdomainmask,                                                                   yes) firstobject]                              stringbyappendingpathcomponent:filename];      [[nsfilemanager defaultmanager] createfileatpath:pathname                                             contents:data                                           attributes:nil]; } 

then in music player want load local url file initialize avplayer:

nsurl *url;     if(_currenttrack.is_local_item)     {           url = [nsurl fileurlwithpath:_currenttrack.local_file_path];     } 

url not created avplayer not play. furthermore, have tried every different way load file data nsdata object check byte size trying access file data returns nil. however, file exists if use nsfilemanager able iterate on items in documents directory , print file names/paths, validating path have saved in "_currenttrack.local_file_path" exist. again, if play file after saving file disk play back.

if there more info can provide make clearer will. thank much.

do not write full directory path db. change. need save file name db reference. use follows:

nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentspath = [paths objectatindex:0];  nsstring *filename = @"saved_file_name.mp3"; // eg: [track_id].mp3 nsstring *filepath = [documentspath stringbyappendingpathcomponent:filename];  

this provide actual path of file.

keep coding........... :)


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -