Skip to content

Instantly share code, notes, and snippets.

@stevenhuey
stevenhuey / CBCosmDatastream.m
Created October 25, 2012 14:58
After Mantle
@implementation CBCosmDatastream
#pragma mark - Mantle
+ (NSDictionary *)externalRepresentationKeyPathsByPropertyKey
{
return [super.externalRepresentationKeyPathsByPropertyKey mtl_dictionaryByAddingEntriesFromDictionary:@{
@"datastreamId": @"id",
@"updated": @"at",
@"value": @"current_value",
@stevenhuey
stevenhuey / CBCosmDatastream.m
Created October 25, 2012 14:57
Before Mantle
@implementation CBCosmDatastream
- (id)initWithAttributes:(NSDictionary*)attributes
{
self = [super init];
if (self)
{
if (!attributes)
{
@stevenhuey
stevenhuey / gist:3023792
Created June 30, 2012 13:44
Set the audio mix
// Build and apply an audio mix using our volume values
- (void)applyAudioMix
{
AVMutableAudioMix* mix = [AVMutableAudioMix audioMix];
NSMutableArray* inputParameters = [[NSMutableArray alloc] initWithCapacity:0];
[_audioMixTrackIDs enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL*stop) {
AVAssetTrack* track = [self trackWithId:(CMPersistentTrackID)[(NSNumber*)obj integerValue]];
@stevenhuey
stevenhuey / gist:3023789
Created June 30, 2012 13:43
Set the volume
// Set the volumne (0.0 - 1.0) for the given track
- (void)setVolume:(float)volume forTrack:(NSString*)audioTrackName
{
[_audioMixValues setValue:[NSNumber numberWithFloat:volume] forKey:audioTrackName];
}
@stevenhuey
stevenhuey / gist:3023786
Created June 30, 2012 13:42
Slider Action
// Action for our 4 sliders
- (IBAction)mix:(id)sender
{
UISlider* slider = (UISlider*)sender;
[self setVolume:slider.value
forTrack:[NSString stringWithFormat:@"track%d", slider.tag]];
[self applyAudioMix];
}
@stevenhuey
stevenhuey / gist:3023783
Created June 30, 2012 13:41
AVPlayer KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"status"])
{
if (AVPlayerItemStatusReadyToPlay == _player.currentItem.status)
{
[_player play];
}
}
}
@stevenhuey
stevenhuey / gist:3023781
Created June 30, 2012 13:40
Creating our AVMutableComposition and AVPlayer
// Setup
_composition = [AVMutableComposition composition];
_audioMixValues = [[NSMutableDictionary alloc] initWithCapacity:0];
_audioMixTrackIDs = [[NSMutableDictionary alloc] initWithCapacity:0];
// Insert the audio tracks into our composition
NSArray* tracks = [NSArray arrayWithObjects:@"track1", @"track2", @"track3", @"track4", nil];
NSString* audioFileType = @"wav";