Skip to content

Instantly share code, notes, and snippets.

@drart
Created June 2, 2013 19:15
Show Gist options
  • Save drart/5694547 to your computer and use it in GitHub Desktop.
Save drart/5694547 to your computer and use it in GitHub Desktop.
Media Player example.
//
// C4WorkSpace.m
// MediaPlayr
//
// Created by Adam Tindale on 2013-06-02.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace
{
C4Movie * movie;
C4Slider * timeline;
C4Timer * timer;
C4Button * playsoundfile;
C4Sample * sound;
}
-(void)setup
{
movie = [C4Movie movieNamed:@"inception.mov"];
[movie setWidth: self.canvas.width];
[movie setCenter:CGPointMake(self.canvas.center.x, movie.height/2)];
[self.canvas addSubview:movie];
movie.shouldAutoplay = YES; // redundant though the following doesn't work
//[movie play];
timeline = [C4Slider slider:CGRectMake(0, 0, self.canvas.width, 10)];
[timeline setCenter:CGPointMake(self.canvas.center.x, movie.height)];
[timeline runMethod:@"blarg:" target:self forEvent:VALUECHANGED];
[self.canvas addSubview:timeline];
playsoundfile = [C4Button buttonWithType:ROUNDEDRECT];
playsoundfile.center = CGPointMake(self.canvas.center.x, movie.height + timeline.height + playsoundfile.height);
[playsoundfile runMethod:@"playsound" target:self forEvent:TOUCHDOWN];
[self.canvas addSubview:playsoundfile];
sound = [C4Sample sampleNamed:@"C4Loop.aif"];
timer = [C4Timer automaticTimerWithInterval:.1 target:self method:@"blarg" repeats:YES];
}
-(void) blarg:(C4Slider *) sender
{
[movie seekToTime:sender.value * movie.duration];
}
-(void) blarg
{
timeline.value = movie.currentTime / movie.duration;
}
-(void) playsound
{
if ( [sound isPlaying])
[sound stop];
else
[sound play];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment