It seems like the video start time ( eg https://www.youtube.com/watch?v=QSCbpcpjJl4&t=1m20s ) is ignored when used in the field. Not sure if it's a bug or whether it is not supported yet. Ideas?

Also, from #2540142: Optional Start-Time Parameter Field:

It would be a tiny nice - and in opinion in some cases extremely useful - feature to (optionally) be able to enter a start time of the video, like YouTube allows also for embedded videos.

Is there any chance you could implement this feature in the (near) future? :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

babusaheb.vikas’s picture

Hi Vacilando,

Start time parameter will work, when you use this format to play video.

<iframe width="520" height="320" wmode="transparent" src="http://www.youtube.com/embed/QSCbpcpjJl4?start=80" type="application/x-shockwave-flash" frameborder="0" allowfullscreen></iframe>

where 80 refers to the second from which you want to start the video.

Additional Hints:----

1) Put video URL like https://www.youtube.com/watch?v=QSCbpcpjJl4?start=80 in cck field.
2) explode video id from URL.
ex:--- $video_id =explode('v=',$row->field_video_url);
3) pass this video id in embed video player
ex:--- <iframe width="520" height="320" wmode="transparent" src="http://www.youtube.com/embed/<?php print $video_id;?>" type="application/x-shockwave-flash" frameborder="0" allowfullscreen></iframe>

I hope your problem will solve.

guschilds’s picture

Hey Vacilando,

When a YouTube URL is provided to a field, two things are saved:

  1. The supplied URL, such as https://www.youtube.com/watch?v=QSCbpcpjJl4&t=1m20s
  2. The video ID that was stripped from that URL, such as QSCbpcpjJl4

When the embed code is constructed in theme_youtube_video(), the URL of the video is constructed with the video ID (#2) and with parameters from the module's configuration and the field's display setting. The supplied URL (#1) is not used at all so any additional parameters it was given are ignored.

That being said, since the additional parameters are kept in the database, it would be possible to read them in theme_youtube_video() and use any that exist. Parameters supplied to the field that are also set by configuration could override the chosen configuration (hopefully they weren't supplied unintentionally in which case this could be confusing). This would allow users to apply specific parameters (not just t, but any of them) to specific videos.

That would be the most reasonable approach. What do you think about that? Any chance you could create a patch?

guschilds’s picture

Issue summary: View changes

Added request from duplicate issue, #2540142: Optional Start-Time Parameter Field, to this issue's description.

simon_s’s picture

FileSize
1.01 KB

Hi Guschilds

I just created a tiny patch that respects a start time offset if present in the youtube url.
For example if you add &start=30 to a Youtube-URL the video will start at 30 seconds.

Probably this implementation is too dirty, since it adds the start time parameter to the video_id variable in youtube_field_formatter_view. But it works and only adds one line of code.

Please tell me what you think.

Cheers & thanks for the nice module!
Simon

simon_s’s picture

I created a new patch that also respects the end parameter, so that you can embed a video with a certain play duration.
E.g. if you add &start=15&end=30 to your Youtube-URL the video plays from second 15 and stops at second 30.

guschilds’s picture

Status: Active » Needs review
FileSize
2.77 KB

Hi simon_s,

Thanks for the patch. As you suspected in #4, adding the parameters to the URL in this way isn't a good idea. The primary reason is because more parameters are added to the URL later in theme_youtube_video() by passing an array to url() and the video ID shouldn't already have parameters attached to it - especially because the first has to use ? and the rest are separated by &.

I've attached a patch that takes the approach outlined in #2. It adds a new setting at admin/config/media/youtube called "Allow users to override parameters." When that is enabled the start time, end time, and any other parameters passed to the initial field value will be added to the URL of the resulting embedded video. This has other benefits, like allowing users to override a particular parameter (like autoplay) for a single video when the rest are still set to something else. You'll need to clear cache and enable the setting after applying this patch in order to test it. Please give it a shot and let me know what you think.

Thanks,
Gus

Vacilando’s picture

I confirm that the patch in #6 works however, it could be slightly and I think simply improved:

  1. The actual start parameter for YouTube seems to be "t" instead of "start". Maybe better to use that rather than "start".
  2. If duration exceeds 60s YouTube uses minutes and hours, e.g. 4h5m15s. I propose to expect and parse such notation rather than simply the number of seconds.
guschilds’s picture

Vacilando,

Thanks for testing and responding!

I originally had the same thought as you. I hadn't heard of "start" until the comment in #4. I'd only heard of "t". When visiting a direct URL, such as https://www.youtube.com/watch?v=1SqBdS0XkV4, appending both "t" and "start" to that URL appear to work. I'd normally prefer "t" because YouTube always gives you "t" when you right click the video and select "Copy video URL at current time" and it is more common.

Oddly enough, when embedding a video with an iframe, "start" is the only one that seems to work. The patch is actually written in a way that, when the module is enabled, it will respect any parameter. This means that with the patch applied, you can try adding &t=4h5m15s to the field's value and if "t" would work, it would. For example, you can add &autoplay=1 to a field's value and that video will autoplay when it otherwise wouldn't have. In all of my testing, '"t" hasn't worked. If I remember correctly, I even tried an embed in a static HTML file (that the module had nothing to do with) and it still didn't work.

That is why I went with "start" over "t". I was bummed because it is less common, but at the same time, I think it is clearer to those who are not as familiar with YouTube.

Unless I'm mistaken, users will have to use "start" if they want this feature.

guschilds’s picture

Title: Start time parameter ignored » Allow users to override parameters on individual videos

Updated the title to reflect what the patch in #6 actually does because I think it could be useful for a lot more than the original topic. After applying the patch and enabling the "Allow users to override parameters." option in the global configuration, users can add parameters to the end of an individual video field value, and those parameters will be respected (they're normally stripped off and ignored). For example, you can add &autoplay=1 to a single field's value and that video will autoplay when it otherwise wouldn't have. Please leave a comment if you end up using this patch and I may consider making it a part of the module.

webservant316’s picture

Excellent addition. Patch #6 works for me and was greatly needed. I am building a training website and in some cases a video is the only page content and I just want to autoplay. However, in other cases I need the student to read a paragraph and then view the video.

Thanks!

  • guschilds committed af5645e on 7.x-1.x
    Issue #2432933 by simon_s, Vacilando, webservant316, guschilds: Allow...

  • guschilds committed 133a1b0 on 8.x-1.x
    Issue #2432933 by simon_s, Vacilando, webservant316, guschilds: Allow...
guschilds’s picture

Status: Needs review » Fixed

Thanks webservant316. Happy to hear it! I went ahead and committed the patch to the 7.x-1.x branch, and a Drupal 8 port of it to the 8.x-1.x branch. They will be available in the next releases!

webservant316’s picture

super

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mtoscano’s picture

Hi,
in case someone is struggling to use it, this feature works just with the long YouTube format: https://youtube.com/watch?v=XXXXXXX&start=30 and not with the short https://youtu.be/XXXXXXXX?start=30.