Module: Mira::Viddler

Defined in:
lib/mira/embed_code.rb

Class Method Summary collapse

Class Method Details

.embed_code(options = {}) ⇒ Object

Returns proper HTML code for embedding

options hash could contain:

  • id: Viddler ID of the video to display (required);

  • player_type: The type of player to embed, either “simple” or “player” (default);

  • width: The width of the player (default is 437);

  • height: The height of the player (default is 370);

  • autoplay: Whether or not to autoplay the video, either

    "t" or "f" (default is "f");
    
  • playAll: Set to “true” to enable play all player (requires

    player_type to be "player");
    

Any additional options passed to the method will be added as flashvars

Example:

Mira::Viddler.embed_code(:player_type => 'simple',
                         :width => 300,
                         :height => 300,
                         :autoplay => 't',
                         :id => "e75e65b2")

Returns embed code for auto playing video e75e65b2 in simple player with 300px width and height



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mira/embed_code.rb', line 29

def self.embed_code(options={})
  raise "hell" unless options[:id]
  options = {
              :player_type => 'player',
              :width => 437,
              :height => 370,
              :autoplay => 'f',
              :wmode => 'transparent'
            }.merge(options)

  # get non flashvars from options
  player_type = options.delete(:player_type)
  width       = options.delete(:width)
  height      = options.delete(:height)
  wmode       = options.delete(:wmode)
  id          = options.delete(:id)

  flashvars = options.collect{|key,value| "#{key}=#{value}"}.join('&')

  html = <<-CODE
  <!--[if IE]>
    <object width="#{width}" height="#{height}" id="viddlerOuter-#{id}" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
      <param name="movie" value="http://www.viddler.com/#{player_type}/#{id}/">
      <param name="allowScriptAccess" value="always">
      <param name="allowNetworking" value="all">
      <param name="allowFullScreen" value="true">
      <param name="wmode" value="#{wmode}" />
      <param name="flashVars" value="#{flashvars}">
      <object id="viddlerInner-#{id}">
        <video id="viddlerVideo-#{id}" src="http://www.viddler.com/file/#{id}/html5mobile/" type="video/mp4" width="#{width}" height="#{height}" poster="http://www.viddler.com/thumbnail/#{id}/" controls="controls"></video>
      </object>
    </object>
  <![endif]-->
  <!--[if !IE]> <!-->
    <object width="#{width}" height="#{height}" id="viddlerOuter-#{id}" type="application/x-shockwave-flash" data="http://www.viddler.com/player/#{id}/"> 
      <param name="movie" value="http://www.viddler.com/#{player_type}/#{id}/"> 
      <param name="allowScriptAccess" value="always">
      <param name="allowNetworking" value="all">
      <param name="allowFullScreen" value="true">
      <param name="wmode" value="#{wmode}" />
      <param name="flashVars" value="#{flashvars}">
      <object id="viddlerInner-#{id}">
        <video id="viddlerVideo-#{id}" src="http://www.viddler.com/file/#{id}/html5mobile/" type="video/mp4" width="#{width}" height="#{height}" poster="http://www.viddler.com/thumbnail/#{id}/" controls="controls"></video>
      </object>
    </object>
  <!--<![endif]-->
CODE
end