Class: ScreenRecorder

Inherits:
Object
  • Object
show all
Defined in:
ext/screen_recorder/screen_recorder.c,
lib/screen_recorder/version.rb,
ext/screen_recorder/screen_recorder.c

Overview

Screen recordings, easy as pi.

Things that you need to be concerned about:

  • screen going to sleep (we can resolve this issue later)
  • short recordings (~1 second) don't work too well; it looks like the last bit of the buffer does not get saved so the last ~0.5 seconds are not saved to disk (we could add a 0.5 second sleep)
  • small memory leak when a recording starts on Mountain Lion with MacRuby
  • constantly leaking memory during recording on Lion with MacRuby
  • run loop hack is not needed if code is already being called from in a run loop in MacRuby
  • pausing is not working...not sure why; so it is not exposed for now

Constant Summary collapse

VERSION =
'0.1.4'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.record(*args) {|recorder| ... } ⇒ String

Record the screen while executing the given block

You may optionally specify the path to save the recording to, just as when calling #start.

The path to the recording will be returned. The recorder object is yielded.

Yields:

Yield Parameters:



180
181
182
183
184
185
186
187
# File 'ext/screen_recorder/screen_recorder.c', line 180

static
VALUE
rb_recorder_record(int argc, VALUE* argv, VALUE self)
{
  VALUE recorder = rb_funcall(rb_cRecorder, sel_new, 0);
  rb_recorder_start(argc, argv, recorder);
  return rb_ensure(rb_recorder_yielder, recorder, rb_recorder_stop, recorder);
}

Instance Method Details

#fileString?

Path to the screen recording on disk

This is nil until the screen recording begins.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'ext/screen_recorder/screen_recorder.c', line 141

static
VALUE
rb_recorder_file(VALUE self)
{
  NSString* name = [OBJC_UNWRAP(self).file path];
  VALUE     path;

  if (name) {
    path = rb_str_new_cstr([name cStringUsingEncoding:NSUTF8StringEncoding]);
    [name release];
  }
  else {
    path = Qnil;
  }

  return path;
}

#lengthFloat

Duration of the recording, in seconds



100
101
102
103
104
105
# File 'ext/screen_recorder/screen_recorder.c', line 100

static
VALUE
rb_recorder_length(VALUE self)
{
  return DBL2NUM([OBJC_UNWRAP(self) length]);
}

#sizeFixnum

Size of the recording on disk, in bytes



112
113
114
115
116
117
# File 'ext/screen_recorder/screen_recorder.c', line 112

static
VALUE
rb_recorder_size(VALUE self)
{
  return SIZET2NUM([OBJC_UNWRAP(self) size]);
}

#start(*args) ⇒ Boolean

Synchrnously start recording

You can optionally specify a file name for the recording; if you do not then a default name will be provided in the form ~/Movies/TestRecording-20121017123230.mov (the timestamp will be different for you).



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'ext/screen_recorder/screen_recorder.c', line 57

static
VALUE
rb_recorder_start(int argc, VALUE* argv, VALUE self)
{
  BOOL     result = NO;
  NSString*  path = nil;
  NSURL* path_url = nil;

  switch (argc)
    {
    case 0:
      result = ([OBJC_UNWRAP(self) start]);
      break;
    case 1:
    default:
      path = [NSString stringWithCString:StringValueCStr(argv[0])
                          encoding:NSUTF8StringEncoding];
      path_url = [NSURL fileURLWithPath:path isDirectory:NO];
      result = [OBJC_UNWRAP(self) start:path_url];
      [path release];
      [path_url release];
    }

  return (result ? Qtrue : Qfalse);
}

#started?Boolean

Whether or not the recording has begun

This will be true after calling #start until #stop is called.



88
89
90
91
92
93
# File 'ext/screen_recorder/screen_recorder.c', line 88

static
VALUE
rb_recorder_started(VALUE self)
{
  return ([OBJC_UNWRAP(self) isStarted] ? Qtrue : Qfalse);
}

#stopBoolean

Synchronously stop recording and finish up commiting any data to disk

A recording cannot be #started again after it has been stopped. You will need to start a new recording.



127
128
129
130
131
132
# File 'ext/screen_recorder/screen_recorder.c', line 127

static
VALUE
rb_recorder_stop(VALUE self)
{
  return ([OBJC_UNWRAP(self) stop] ? Qtrue : Qfalse);
}