edubkendo
2/3/2013 - 8:41 AM

Converts http://www.youtube.com/watch?v=bWl98dhvf8Q to JRubyFX.

require "jrubyfx"

class MoviePlayer < JRubyFX::Application
  def start(stage)
    with(stage,title: "Movie Player") do
      my_slider = slider(min: 0.0, value: 0.0)
      slide_in = Timeline.new
      slide_out = Timeline.new

      layout_scene(400, 400, :black)  do
        group do
          set_on_mouse_entered do |event|
            slide_in.play
          end

          set_on_mouse_exited do |event|
            slide_out.play
          end

          media = Media.new("file:///home/eric/projects/jrubyfx_projects/MoviePlayer/trailers/sintel.mp4")
          # media = Media.new("file:///home/eric/media/japanese/anime/senran.mp4")
          player = media_player(media, auto_play: true)
          view = media_view(player)
          my_vbox = vbox do
            children.add(my_slider)
          end

          player.set_on_ready do |event|
            w = player.media.width
            h = player.media.height - 100
            stage.min_width = w
            stage.min_height = h

            my_vbox.set_min_size(w, 100)
            my_vbox.translate_y = (h - 100)
            my_slider.max = player.get_total_duration().to_seconds()

            player.current_time_property.add_change_listener do |obs, dur, current|
              my_slider.set_value(current.to_seconds)
            end

            my_slider.set_on_mouse_clicked do |event|
              player.seek(Duration.seconds(my_slider.get_value))
            end

            in_invisible = key_frame(Duration.new(0),
              key_value(my_vbox.translateYProperty, h),
              key_value(my_vbox.opacity_property, 0.0))

            in_visible = key_frame(Duration.new(300),
              key_value(my_vbox.translateYProperty, h - 100),
              key_value(my_vbox.opacity_property, 0.9))

            out_invisible = key_frame(Duration.new(300),
              key_value(my_vbox.translateYProperty, h),
              key_value(my_vbox.opacity_property, 0.0))

            out_visible = key_frame(Duration.new(0),
              key_value(my_vbox.translateYProperty, h - 100),
              key_value(my_vbox.opacity_property, 0.9))

            slide_out.keyFrames << out_visible << out_invisible
            slide_in.keyFrames << in_invisible << in_visible

          end

        end
      end
    end
    stage.show()
  end
end

MoviePlayer.launch