Video 1.1.0

Glimmer Custom Widget

Video is a Glimmer Custom Widget for playing videos via the video Glimmer DSL keyword.

Platforms

This has been tested and confirmed to be working on: - Mac - Windows

Pre-requisites

Setup

Glimmer Application

Add the following to a Glimmer application Gemfile:

gem 'glimmer-cw-video', '1.1.0'

Run:

jruby -S bundle

(or just bundle if using RVM)

Glimmer Custom Shell or Glimmer Custom Widget

When reusing video custom widget in a Glimmer custom shell or custom widget, you can follow the same steps for Glimmer application, and then add a require statement to your library file:

require 'glimmer-cw-video'
# ... more require statements follow

API Options

Here are the options to pass in as hash arguments to the video widget keyword (see in Samples): - autoplay (true [default] or false): plays video automatically as soon as loaded - controls (true [default] or false): displays controls - looped (true or false [default]): plays video in looped mode - background (Glimmer color [default: white]): sets background color just like with any other widget - fit_to_width (true [default] or false): fits video width to widget allotted width regardless of video's original size. Maintains video aspect ratio. - fit_to_height (true [default] or false): fits video height to widget allotted height regardless of video's original size. Maintains video aspect ratio. - offset_x (integer [default: 0]): offset from left border. Could be a negative number if you want to show only an area of the video. Useful when fit_to_width is false to pick an area of the video to display. - offset_y (integer [default: 0]): offset from top border. Could be a negative number if you want to show only an area of the video. Useful when fit_to_height is false to pick an area of the video to display.

API Methods

API Observer Events

(see in Samples)

Samples

Run this command to list available Video samples:

glimmer sample:list

Hello, Video!

Run:

glimmer sample:run[hello_video]

Glimmer Code (from samples/video/hello_video.rb):

require_relative '../../lib/glimmer-cw-video'

include Glimmer

video_file = File.expand_path('../videos/Clouds_passing_by_CCBY_NatureClip.mp4', __FILE__)

shell {
  text 'Hello, Video!'
  minimum_size 384, 240
  
  video(file: video_file)
}.open

Glimmer App:

Hello, Looped Video with Black Background!

Run:

glimmer sample:run[hello_looped_video_with_black_background]

Glimmer Code (from samples/video/hello_looped_video_with_black_background.rb):

require_relative '../../lib/glimmer-cw-video'

include Glimmer

video_file = File.expand_path('../videos/Blackpool_Timelapse.mp4', __FILE__)

shell {
  text 'Hello, Looped Video with Black Background!'
  minimum_size 1024, 640

  video(file: video_file, looped: true, background: :black)
}.open

Glimmer App:

Hello, Video Observers!

Run:

glimmer sample:run[hello_video_observers]

Glimmer Code (from samples/video/hello_video_observers.rb):

require_relative '../../lib/glimmer-cw-video'

include Glimmer

video_file = File.expand_path('../videos/Ants.mp4', __FILE__)

def display_video_status(video, status)
  message_box {
    text status
    message "#{video.position.round(2)}/#{video.duration.round(2)} seconds have elapsed."
  }.open
end

@shell = shell {
  text 'Hello, Video Observers!'
  minimum_size 800, 500

  @video = video(file: video_file, background: :black) {
    on_swt_show { |event|
      # set focus as soon as the SWT widget is shown to grab keyboard events below
      @video.set_focus
    }
    
    on_key_pressed { |event|
      case event.keyCode
      when swt(:space), swt(:cr)
        @video.toggle
      when swt(:arrow_left)
        @video.rewind
      when swt(:arrow_right)
        @video.fast_forward
      when swt(:arrow_up)
        @video.volume_up
      when swt(:arrow_down)
        @video.volume_down
      end
    }   
    
    on_playing {
      display_video_status(@video, 'Playing')
    }
    
    on_paused {
      display_video_status(@video, 'Paused')
    }
    
    on_ended {
      display_video_status(@video, 'Ended')
    }
  }
}
@shell.open

Glimmer App:

Dialog for video playing event:

Dialog for video paused event:

Dialog for video ended event:

TODO

TODO.md

Change Log

CHANGELOG.md

Contributing to glimmer-cw-video

License

MIT

Copyright © 2020 - Andy Maleh.

Built for Glimmer (Ruby Desktop Development GUI Library).