Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>AVAudioPlayer should not be added to a persistant store in core-data since it does not conform to the NSCoding protocol.</p> <p>What I would do is remove the AVAudioPlayer from your model but keep it in your NSManagedObject. Then in the implementation switch @dynamic to @synthesized for the audioPlayer. (Add a line too to release the audio player on dealloc).</p> <p>Then do something like this</p> <pre><code>-(AVAudioPlayer*)audioPlayer { if (self.audioPlayer) return audioPlayer; else { NSError * error = nil; AVAudioPlayer * lAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.fileURL error:&amp;error]; if (!error) { self.audioPlayer = lAudioPlayer; [lAudioPlayer release]; } else { [lAudioPlayer release]; NSLog(@"%@",error); } } } </code></pre> <p>I would also recommend to something similar with isLooping and duration and have them come off the audioPlayer directly and not store them in your persistant store unless you need them to persist.</p> <p>EDIT</p> <p>Sounds like your problem is that you are referencing the avaudioplayer in your object (for persistance sake) then saving the context then later when you come back you are rerequesting the object from the persistant store, this will not work since your persistant store can not handle avaudioplayer. There are multiple ways to solve this problem.</p> <p>The first is to store all your avaudioplayers in a nsmutabledictionary (i would make it static or in a singleton). This nsmutabledictionary would be keyed by a unique identifier. You can either create a unique identifier and store it in your persistent store (with a new attribute on your object) or just use the objectid of the sound object (I believe). At that point do what I said before about making the audioPlayer in your managed object class but instead of creating it there just get it back from the nsmutabledictionary with the unique identifier that was made, if there is none that means you need to make a new audio player and add it to the nsmutabledictionary.</p> <p>I hope I am understanding your problem, I think this is the easiest solution and also the most elegant. The other one that is also really easy is that you keep in memory all the sound managed objects that are playing, like that you won't need to rerequest them from the persistant store and therefor your audioplayer will still be accessible.</p> <p>There are really a thousand ways to do this, I am just giving you the 2 I would use, and don't forget to release your audioplayers and remove them from the mutable dictionary when you are done with them.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload