Class: QuickTime
- Inherits:
-
Object
- Object
- QuickTime
- Defined in:
- lib/quicktime-player-mac/quicktime.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#movie_index ⇒ Object
Returns the value of attribute movie_index.
Instance Method Summary collapse
- #current_time ⇒ Object
- #current_time=(sec) ⇒ Object
-
#initialize(movie_index = 1) ⇒ QuickTime
constructor
A new instance of QuickTime.
- #movies ⇒ Object
- #play ⇒ Object
- #playing? ⇒ Boolean
- #speed ⇒ Object
- #speed=(speed) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(movie_index = 1) ⇒ QuickTime
Returns a new instance of QuickTime.
11 12 13 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 11 def initialize(movie_index=1) @movie_index = movie_index end |
Instance Attribute Details
#movie_index ⇒ Object
Returns the value of attribute movie_index.
9 10 11 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 9 def movie_index @movie_index end |
Instance Method Details
#current_time ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 71 def current_time script = "tell application 'QuickTime Player' tell movie #{@movie_index} get current time end tell end tell".gsub(/'/,'"') res = AppleScript.execute(script) res.to_f/600 end |
#current_time=(sec) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 82 def current_time=(sec) sec = sec*600 script = "tell application 'QuickTime Player' tell movie #{@movie_index} set current time to #{sec} end tell end tell".gsub(/'/, '"') res = AppleScript.execute(script) end |
#movies ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 93 def movies script = "tell application 'QuickTime Player' get documents end tell".gsub(/'/,'"') res = AppleScript.execute(script) end |
#play ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 48 def play script = "tell application 'QuickTime Player' tell movie #{@movie_index} play end tell end tell".gsub(/'/,'"') AppleScript.execute(script) end |
#playing? ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 58 def script = "tell application 'QuickTime Player' tell movie #{@movie_index} playing end tell end tell".gsub(/'/,'"') res = AppleScript.execute(script) return true if res =~ /^true/ return false if res =~ /^false/ raise Error.new("couldn't get playing status") end |
#speed ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 30 def speed script = "tell application 'QuickTime Player' get preferred rate of document 1 end tell".gsub(/'/,'"') AppleScript.execute(script).to_f end |
#speed=(speed) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 15 def speed=(speed) raise ArgumentError.new('speed should be Number') if speed.class != Fixnum and speed.class != Float @speed = speed script = "tell application 'QuickTime Player' set preferred rate of document 1 to #{speed} tell movie #{@movie_index} if playing then play end if end tell end tell".gsub(/'/,'"') AppleScript.execute(script) end |
#stop ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/quicktime-player-mac/quicktime.rb', line 38 def stop script = "tell application 'QuickTime Player' tell movie #{@movie_index} stop end tell end tell".gsub(/'/,'"') AppleScript.execute(script) end |