Skip to content
This repository

Youtube: autoplay and hide related #58

Merged
merged 2 commits into from 3 months ago

4 participants

Alexey Denisov LightBe Corp Dejan Simic Shivakumaar Mgs
Alexey Denisov

Added options to hide related videos when playback ends and to autoplay video when the player loads.

New youtube options

autoplay: true, false (by default false)
hide_related: true, false (by default false)
LightBe Corp

Do these options work? I'm running version 1.6.0. I have done this in my model:

youtube(:width => 640, :height => 360, :autoplay => false, :hide_related => true)

Thumbnails still appear for related videos instead of the default thumbnail for the video when I embed directly from YouTube with ?rel=0 at the end of the link.

Alexey Denisov

It works, but this functionality doesn't merged into upstream...

LightBe Corp

I forget the version of the gem I started with. It would have been before these options were added. That I know. Do I need to start over and create a new database to get this working?

Dejan Simic dejan merged commit 77d8b8a into from
Dejan Simic dejan closed this
Dejan Simic
Owner

Thanks! This will be in 1.6.2 due in few days.

Shivakumaar Mgs

how to autohide the controls in youtube player

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4  README.md
Source Rendered
@@ -27,7 +27,7 @@ You'll probably have user input stored in model, so it's a good place to automat
27 27
       auto_html_for :body do
28 28
         html_escape
29 29
         image
30  
-        youtube(:width => 400, :height => 250)
  30
+        youtube(:width => 400, :height => 250, :autoplay => true)
31 31
         link :target => "_blank", :rel => "nofollow"
32 32
         simple_format
33 33
       end
@@ -120,4 +120,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
120 120
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
121 121
 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
122 122
 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
123  
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  123
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12  lib/auto_html/filters/youtube.rb
... ...
@@ -1,4 +1,4 @@
1  
-AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil) do |text, options|
  1
+AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil, :autoplay => false, :hide_related => false) do |text, options|
2 2
   regex = /https?:\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\S)*/
3 3
   text.gsub(regex) do
4 4
     youtube_id = $3
@@ -6,8 +6,14 @@
6 6
     height = options[:height]
7 7
     frameborder = options[:frameborder]
8 8
 		wmode = options[:wmode]
9  
-		src = "//www.youtube.com/embed/#{youtube_id}"
10  
-		src += "?wmode=#{wmode}" if wmode
  9
+    autoplay = options[:autoplay]
  10
+    hide_related = options[:hide_related]
  11
+		src = "//www.youtube.com/embed/#{youtube_id}?"
  12
+    params = []
  13
+		params << "wmode=#{wmode}" if wmode
  14
+    params << "autoplay=1" if autoplay
  15
+    params << "rel=0" if hide_related
  16
+    src += params.join '&' unless params.empty?
11 17
     %{<iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe>}
12 18
   end
13 19
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.