Class: Shoes::Video

Inherits:
Object show all
Defined in:
lib/plugins/video.rb

Constant Summary collapse

JFile =
java.io.File

Instance Method Summary collapse

Constructor Details

#initialize(path, args) ⇒ Video

Returns a new instance of Video.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/plugins/video.rb', line 21

def initialize path, args
  args.each do |k, v|
    instance_variable_set "@#{k}", v
  end
  Video.class_eval do
    attr_accessor *args.keys
  end
  
  if path =~ /^(http|https):\/\//
    @save ||= File.basename path
    app.download(path, save: @save){init @save}
  else
    init path
  end
end

Instance Method Details

#init(file) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/plugins/video.rb', line 37

def init file
  if File.extname(file) == '.mpg'
    cs = Swt::Composite.new @app.cs, Swt::SWT::EMBEDDED
    cs.setSize @width, @height
    cs.setLocation Swt::Point.new(@left, @top)
    locator = MediaLocator.new JFile.new(file).toURL
    source = Manager.createDataSource locator
    player = Manager.createRealizedPlayer source
    frame = SWT_AWT.new_Frame cs
    frame.add player.getControlPanelComponent
    frame.add player.getVisualComponent
    frame.pack
  else
    audio = AudioSystem.getAudioInputStream JFile.new file
    format = audio.getFormat
    af = AudioFormat.new AudioFormat::Encoding::PCM_SIGNED, format.getSampleRate, 16, 
      format.getChannels, format.getChannels * 2, format.getSampleRate, false
    as = AudioSystem.getAudioInputStream af, audio
    @line = AudioSystem.getLine DataLine::Info.new(Clip.java_class, af)
    @line.open as
  end
end

#lengthObject



74
75
76
# File 'lib/plugins/video.rb', line 74

def length
  @line.getMicrosecondLength / 1000 if @line
end

#playObject



60
61
62
63
# File 'lib/plugins/video.rb', line 60

def play
  self.time = 0
  start
end

#playing?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/plugins/video.rb', line 94

def playing?
  @line.isRunning if @line
end

#positionObject



86
87
88
# File 'lib/plugins/video.rb', line 86

def position
  time / length.to_f if @line
end

#position=(f) ⇒ Object



90
91
92
# File 'lib/plugins/video.rb', line 90

def position=(f)
  self.time = length * f if @line
end

#startObject



70
71
72
# File 'lib/plugins/video.rb', line 70

def start
  @line.start if @line
end

#stopObject Also known as: pause



65
66
67
# File 'lib/plugins/video.rb', line 65

def stop
  @line.stop if @line
end

#timeObject



78
79
80
# File 'lib/plugins/video.rb', line 78

def time
  @line.getMicrosecondPosition / 1000 if @line
end

#time=(n) ⇒ Object



82
83
84
# File 'lib/plugins/video.rb', line 82

def time=(n)
  @line.setMicrosecondPosition n * 1000 if @line
end