GithubHelp home page GithubHelp logo

andyobtiva / glimmer-cw-video Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 4.64 MB

Video custom widget for Glimmer DSL for SWT

License: MIT License

Ruby 100.00%
glimmer-custom-widget glimmer ruby jruby desktop desktop-widget swt gui macos mac

glimmer-cw-video's Introduction

Video 1.1.0

Gem Version Travis CI Coverage Status Maintainability Join the chat at https://gitter.im/AndyObtiva/glimmer

Video Widget

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

Featured in Math Bowling 2

Math Bowling 2

Platforms

This has been tested and confirmed to be working on:

  • Mac
  • Windows

Pre-requisites

Setup

Glimmer Application

Add the following to a Glimmer DSL for SWT 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 the video custom widget in a Glimmer DSL for SWT custom shell or custom widget, you can follow the same steps for a Glimmer DSL for SWT 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

  • #play: plays video
  • #pause: pauses video
  • #toggle: toggles video playback, playing if paused, and pausing if playing.
  • #reload: reloads video restarting from beginning
  • #position: position in seconds (and fractions)
  • #position=: seeks a new position in video
  • #duration: length of video, maximum video position possible
  • #loaded?: returns true when video has been initially loaded or reloaded
  • #playing?: returns true when video is actively playing
  • #paused?: returns true when video is not playing
  • #ended?: returns true when video has reached the end (position == duration)
  • #volume: returns video volume (0.0 - 1.0 float value)
  • #volume=: sets video volume (0.0 - 1.0 float value)
  • #volume_up(value=0.05): bumps video volume up by a specified value or default
  • #volume_down(value=0.05): bumps video volume down by a specified value or default
  • #mute: mutes video
  • #unmute: unmutes video
  • #muted?: returns true if video is muted
  • #toggle_muted: mutes/unmutes video depending on muted? attribute

API Observer Events

(see in Samples)

  • on_loaded: invoked when video #loaded? becomes true
  • on_ended: invoked when video #ended? becomes true
  • on_playing: invoked when video #playing? becomes true
  • on_paused: invoked when video #paused? becomes true

Samples

Run this command after installing the gem to list available Video samples via the Glimmer Meta-Sample (note that you would have to restart the Glimmer Meta-Sample after every Video sample run because of an unresolved minor issue):

glimmer samples

Hello, Video!

Run from Glimmer Meta-Sample or by cloning this project and executing:

glimmer samples/video/hello_video.rb

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:

glimmer cw video hello video

Hello, Looped Video with Black Background!

Run from Glimmer Meta-Sample or by cloning this project and executing:

glimmer samples/video/hello_looped_video_with_black_background.rb

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:

glimmer cw video hello video

Hello, Video Observers!

Run from Glimmer Meta-Sample or by cloning this project and executing:

glimmer samples/video/hello_video_observers.rb

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:

glimmer cw video hello video observers

Dialog for video playing event:

glimmer cw video hello video observers

Dialog for video paused event:

glimmer cw video hello video observers

Dialog for video ended event:

glimmer cw video hello video observers

TODO

TODO.md

Change Log

CHANGELOG.md

Contributing to glimmer-cw-video

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

License

MIT

Copyright (c) 2020-2023 - Andy Maleh.

--

Built for Glimmer DSL for SWT (JRuby Desktop Development GUI Framework).

glimmer-cw-video's People

Contributors

andyobtiva avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

rubycoder

glimmer-cw-video's Issues

Couldn't use with glimmer-dsl-swt

My Gemfile:

gem 'matrix'
gem 'glimmer-dsl-swt'
gem 'glimmer-cw-video'

(I have expliticitly declare matrix - somehow not declared as dependencies of glimmer-cw-video)

Here is the code I tried to run

require 'glimmer-dsl-swt'
require 'glimmer-cw-video'

include Glimmer
    shell {
      text 'Hello, Video!'
      minimum_size 384, 240
      video
    }.open

Result:

[2023-06-11 07:46:39] ERROR glimmer: /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/xml_visitor.rb:83:in `block in append_attributes': undefined method `xml_attribute_underscore' for Glimmer::Config:Module (NoMethodError)
	from org/jruby/RubyHash.java:1587:in `each'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/xml_visitor.rb:80:in `append_attributes'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/html_visitor.rb:57:in `append_attributes'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/xml_visitor.rb:41:in `process_before_children'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/depth_first_search_iterator.rb:37:in `process'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/depth_first_search_iterator.rb:38:in `block in process'
	from org/jruby/RubyArray.java:1987:in `each'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/depth_first_search_iterator.rb:38:in `process'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/depth_first_search_iterator.rb:38:in `block in process'
	from org/jruby/RubyArray.java:1987:in `each'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/depth_first_search_iterator.rb:38:in `process'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/depth_first_search_iterator.rb:33:in `iterate'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-xml-1.3.1/lib/glimmer/xml/html_node.rb:32:in `to_xml'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-swt-4.21.2.1/lib/glimmer/swt/widget_proxy.rb:1145:in `block in property_type_converters'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-swt-4.21.2.1/lib/glimmer/swt/widget_proxy.rb:1033:in `apply_property_type_converters'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-swt-4.21.2.1/lib/glimmer/swt/widget_proxy.rb:255:in `block in set_attribute'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-swt-4.21.2.1/lib/glimmer/swt/display_proxy.rb:151:in `auto_exec'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-swt-4.21.2.1/lib/glimmer/swt/widget_proxy.rb:608:in `auto_exec'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-swt-4.21.2.1/lib/glimmer/swt/widget_proxy.rb:254:in `set_attribute'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-swt-4.21.2.1/lib/glimmer/dsl/swt/property_expression.rb:40:in `interpret'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/engine.rb:181:in `block in interpret_expression'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/expression.rb:64:in `around'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/engine.rb:180:in `interpret_expression'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/engine.rb:175:in `interpret'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/engine.rb:48:in `block in Engine'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-cw-video-1.1.0/lib/views/glimmer/video.rb:31:in `block in Video'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/parent_expression.rb:32:in `add_content'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-swt-4.21.2.1/lib/glimmer/dsl/swt/widget_expression.rb:51:in `add_content'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/engine.rb:199:in `add_content'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/engine.rb:182:in `block in interpret_expression'
	from org/jruby/RubyKernel.java:2019:in `tap'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/engine.rb:181:in `block in interpret_expression'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/expression.rb:64:in `around'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/engine.rb:180:in `interpret_expression'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer/dsl/engine.rb:175:in `interpret'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-2.4.1/lib/glimmer.rb:78:in `method_missing'
	from /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-cw-video-1.1.0/lib/views/glimmer/video.rb:30:in `block in Video'

Somewhere down there is another exception:

NoMethodError: undefined method `swt_widget' for true:TrueClass
            initialize at /Users/phuongnd08/.asdf/installs/ruby/jruby-9.4.2.0/lib/ruby/gems/shared/gems/glimmer-dsl-swt-4.21.2.1/lib/glimmer/ui/custom_widget.rb:184
                   new at org/jruby/RubyClass.java:931

[Documentation] Implementation Details?

Hey there Andy,

If you have some time and feel motivated, how was this made? Could this be
added to some docu-file or the wiki, if you have time?

I remember you mentioned this a while ago; I am surprised that this already
works ... I am kind of missing the in-between stuff so I am a bit confused.
Have to find out how that works and what limitations/opportunities are
possible now (other than, of course, viewing videos).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.