-2

I have a problem in playing audio file from URL in the background while the iPhone is locked. my app plays podcasts, but while it is playing the podcast at specific second the podcast will stop and an ad will play, the ad consist of three audio tracks, first and last are the messages "please wait, ad will play" and "thanks, your track will complete now", and the middle track is the ad it self from URL. I tried to make two AVPlayers one for track and the other for the ad, and I tried to make four players for each track, the process works well if the app is running, but when the iPhone is locked, just the first message starts, and nothing happen after.

any suggestions !!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ahmed Adnan Qazzaz
  • 333
  • 1
  • 3
  • 15
  • Possible duplicate of [How to handle background audio playing while iOS device is locked or on another application?](http://stackoverflow.com/questions/10429204/how-to-handle-background-audio-playing-while-ios-device-is-locked-or-on-another) – Teja Nandamuri Jun 23 '16 at 13:00
  • @TejaNandamuri I think this topic talks about playing sound in the background, I don't have problem with playing sound in background, the problem when I stop the main sound and starts ad to play, it is not works well – Ahmed Adnan Qazzaz Jun 23 '16 at 13:14

1 Answers1

0

Finally I found the solution of my problem, When I save the ad file I use [file writeToFile: atomically:], but the app can't reach the document directory when the device locked for a long time unless the file is in the noneProtection mode, so I use [file writeToFile:filePath options:NSDataWritingFileProtectionNone error:nil];

It Works :)

Ahmed Adnan Qazzaz
  • 333
  • 1
  • 3
  • 15