开发者

How should I save the state of an audio file when the user suspends my application?

开发者 https://www.devze.com 2023-01-22 22:04 出处:网络
In my app I need to play a 50 MB audio story.If at about the 27 minute mark the user hits the home button, the sound pauses.When they resume the application, the audio resumes where it left off.

In my app I need to play a 50 MB audio story. If at about the 27 minute mark the user hits the home button, the sound pauses. When they resume the application, the audio resumes where it left off.

I'm using AVAudioPlayer to play this audio, but I'm worried about keeping this la开发者_C百科rge audio file in memory when my application goes to the background. What would you recommend for minimizing the memory impact of saving / resuming state for an audio file like this?


I would suggest you stick with AVAudioPlayer for something of such size. One thing you can do is to put handling in your app delegate to free your audio in the applicationDidReceiveMemoryWarning method. The OS will send that call if your app is backgrounded and it needs more heap memory and that way you can gracefully deal with the issue.

Presumably you just read the currentTime property when backgrounded and then set it when you want to continue your app. If you do this you could, potentially, just free up your memory on an interrupt and try to re-create your player when you wake back up, but I'd personally just stick with only freeing when you get the memory warning.

And as for OpenAL, it's great for short sounds that you want to play quickly, but I'd suggest you stay away from it for anything longer than just a couple of seconds, max.


The operating system will kill your app (and reclaim its memory) if necessary, so I wouldn’t be worried about Apple rejecting it on those grounds.


You should use OpenAL: http://www.gamedev.net/reference/articles/article2008.asp

Then set AL_SEC_OFFSET (seconds offset) to the stored position in order to begin where the user left off.

0

精彩评论

暂无评论...
验证码 换一张
取 消