My goal is to store the reference of an audioPlayer instance in core data in that way, that i can use properties on that entry later. like this:
-(void)didTapButton
{
if (!self.sound.audioPlayer.playing)
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"playSound" object:self.sound];
self.soundProgress.hidden = NO;
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:@"stopSound" object:self.sound];
self.soundProgress.hidden = YES;
}
}
My MOS looks like this
@interface MCSound : NSManagedObject
@property (nonatomic, retain) AVAudioPlayer *audioPlayer;
@property (nonatomic, retain) NSString * category;
@property (nonatomic, retain) NSString * duration;
@property (nonatomic, retain) NSString * fileURL;
@property (nonatomic, retain) NSString * id;
@property (nonatomic, retain) NSNumber * isLooping;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * theme;
@property (nonatomic, retain) MCTheme *ofTheme;
@end
That works so far. But if i'd generate again the MOSs the AVAudioPlayer Class would be replaced by id. Is there a way how i can do that with categories? Would i have to use after that of the category the category for my sound instances?
EDIT
I need a reference to AVAudioPlayer while the app is running as i'm switching views a lot and the AVAudioPlayer are initialized one gridView. Structure is:
gridView -> detailView -> soundButton
Buttons send a notification to gridView where the AVAudioPlayer is instatiated. When i come back to the detailView i have to show if a sound is still playing and the playingTime must be shown on a progressBar. I had that all using a NSMutableDisctionary but now switching to a core data model cause i have to prefill the data base with default sound sets.
And therefore i thought its the best way to plase the reference to the AVAudioPlayer in the sound records. Because need the reference of the audioPlayer when i come back to the detailView. I have to know if it is still playing and the playingTime.
How would you solve that?