I have a requirement where i have a Video that is played using MPMediaPlayerController. Along with the video i have two buttons where i need to capture the current playback time when the button are clicked and store all the relevant clicks individually. I am able to get the current playback time of the video using “currentPlaybackTime” property which returns NSTimeInterval. But can someone help me in how to store all the NSTimeInterval values into an NSMutableDictionary. I have tried the following ways:
-(void)onClickOfGood {
NSLog(@"The current playback time in good:%g",moviePlayerController.currentPlaybackTime);
currentPlaybackTime = moviePlayerController.currentPlaybackTime;
//NSArray *arrayContainsGoodClicks = [[NSArray alloc]initWithObjects:currentPlaybackTime, nil ];
NSNumber *goodTimeIntervals = [NSNumber numberWithDouble:currentPlaybackTime];
NSMutableArray *arrayContainsGoodClicks = [[NSMutableArray alloc]initWithObjects:goodTimeIntervals,nil ];
NSLog(@"The total count of Array is: %i",[arrayContainsGoodClicks count]);}
But everytime after the click of good button i am getting the Array count as only 1. Can someone please throw a light on where i am going wrong?
This is not surprising, considering that you are creating a brand-new
NSMutableArrayon the previous line.To fix this, you need to make
NSMutableArray *arrayContainsGoodClicksan instance variable (AKA ivar), initialize it to[NSMutableArray array]in your designated initializer, and then useto add objects to the array.
If you are looking to use
NSMutableDictionaryinstead, the strategy would be identical, except you would need to decide on an object that you would like to use as unique keys to yourNSDictionary. Also remember thatNSMutableDictionaryis not ordered, so you might need to take care of sorting each time you display your dictionary items to users.