Skip to content

Instantly share code, notes, and snippets.

@stevenhuey
stevenhuey / gist:3023781
Created Jun 30, 2012
Creating our AVMutableComposition and AVPlayer
View gist:3023781
// 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";
View gist:3023783
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"status"])
{
if (AVPlayerItemStatusReadyToPlay == _player.currentItem.status)
{
[_player play];
}
}
}
View gist:3023786
// 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];
}
View gist:3023789
// 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:3023792
Created Jun 30, 2012
Set the audio mix
View gist:3023792
// 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]];
View CBCosmDatastream.m
@implementation CBCosmDatastream
- (id)initWithAttributes:(NSDictionary*)attributes
{
self = [super init];
if (self)
{
if (!attributes)
{
View CBCosmDatastream.m
@implementation CBCosmDatastream
#pragma mark - Mantle
+ (NSDictionary *)externalRepresentationKeyPathsByPropertyKey
{
return [super.externalRepresentationKeyPathsByPropertyKey mtl_dictionaryByAddingEntriesFromDictionary:@{
@"datastreamId": @"id",
@"updated": @"at",
@"value": @"current_value",
View sugar.m
[@3 times:^{
NSLog(@"Hello World!");
}];
// Hello World!
// Hello World!
// Hello World!
View sugar2.m
NSArray *cars = [@"Testarossa", @"F50", @"F458 Italia"];
// or NSSet *cars = [NSSet setWithObjects:@"Testarossa", @"F50", @"F458 Italia", nil];
[cars map:^id(id car){
return @([[car substringToIndex:1] isEqualToString:@"F"]);
}];
// NO (Testarossa)
// YES (F50)
// YES (F458 Italia)
@stevenhuey
stevenhuey / PonyDebuggerSetup.m
Created Feb 9, 2013
Our changes to the application:didFinishLaunchingWithOptions: method.
View PonyDebuggerSetup.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
fDebugger = [PDDebugger defaultInstance];
[fDebugger enableNetworkTrafficDebugging];
[fDebugger forwardAllNetworkTraffic];
[fDebugger enableCoreDataDebugging];
[fDebugger addManagedObjectContext:self.managedObjectContext withName:@"Popular on 500px"];