Sha256: 0ea5d0be2c4b2bbd4139b341122fe2cefff53aa5d02d3255f9b76813fed83514
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
require "video_player/version" module VideoPlayer def self.player url, width = "420", height = "315", autoplay = true if url.include? "youtube" regex = /(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/ url.gsub(regex) do youtube_id = $4 if autoplay src = "//www.youtube.com/embed/#{youtube_id}?autoplay=1&rel=0" else src = "//www.youtube.com/embed/#{youtube_id}?autoplay=0&rel=0" end return %{<iframe width="#{width}" height="#{height}" src="#{src}" frameborder="0" allowfullscreen></iframe>} end elsif url.include? "vimeo" url.gsub(/https?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/) do vimeo_id = $2 frameborder = 0 return %{<iframe src="//player.vimeo.com/video/#{vimeo_id}" width="#{width}" height="#{height}" frameborder="#{frameborder}"></iframe>} end else return false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
video_player-0.1 | lib/video_player.rb |