MediaElement should support overwriting the YouTube player as demo'd here:
http://mediaelementjs.com/examples/?name=youtube

This is discussed in more detail here:
http://johndyer.name/html5-video-wrapper-for-youtube-and-vimeo-api-media...

Right now it seems we need to use the Media: YouTube module with Media to get a YouTube player which is fine, but I'm looking to develop a consistent player whether a local file is being played or a remote YouTube video - ME can do this, but it doesn't seem the ME Drupal Module is ready for this. It looks like the <video> tags need to wrap a <source> tag with the relevant YouTube URL. Right now, the module produces a <video> with src="" attribute which seems to be breaking with external URLs like YouTube.

Comments

chrisrcooper’s picture

I've hacked around this with a temporary solution that only applies to YouTube and only applies to Video:

In mediaelement.module, original:

function theme_mediaelement_video($variables) {    
  $output = '<div class="mediaelement-video">';
  $output .= '<video ' . drupal_attributes($variables['attributes']) . ' ></video>';	  
  if ($variables['settings']['download_link']) {
    $output .= '<div class="mediaelement-download-link"><a href="' . $variables['attributes']['src'] . '">' . filter_xss_admin($variables['settings']['download_text']) . '</a></div>';
  }
  $output .= '</div>';
  return $output;
}

to:

function theme_mediaelement_video($variables) {    
  $output = '<div class="mediaelement-video">';
  if(strpos($variables['attributes']['src'],"youtube")) {
  	$output .= '<video width="' . $variables['attributes']['width'] . '" height="' . $variables['attributes']['height'] . '" class="' . $variables['attributes']['class'] . '"><source type="video/youtube" src="' . $variables['attributes']['src'] . '" /></video>';
  } else {
	$output .= '<video ' . drupal_attributes($variables['attributes']) . ' ></video>';	  
  }
  if ($variables['settings']['download_link']) {
    $output .= '<div class="mediaelement-download-link"><a href="' . $variables['attributes']['src'] . '">' . filter_xss_admin($variables['settings']['download_text']) . '</a></div>';
  }
  $output .= '</div>';
  return $output;
}

This just checks for "youtube" in the source, and if it's found, moves the "src" attribute to a <source> tag within the <video> tag which ME understands correctly and will wrap itself around the YouTube video. Tested in FFX/Webkit/iPhone/Android for local media + YouTube. There's a far better solution somewhere for someone that understands ME and the Media module better.

jsmm’s picture

Since I get a blank screen and a download link when adding a youtube url to media, I assume Mediaelement cannot stream youtube videos, is this correct or do have I missed some configuration step?

brockfanning’s picture

After adding a Link field and using the theme function override posted by chrisrcooper, it does play Youtube videos. All you have to do is paste the URL of the Youtube video into the link field, and set the link field's display to Media Element Video.

Since the code in #1 doesn't alter the normal behavior of the module, I think it makes sense as an added feature. I suppose the other option is to revamp the architecture of the module and make the Youtube functionality into a plugin type of thing. But I like the simplicity and out-of-the-box-ness of this module, so would be more inclined to see it added as a bonus feature that just works. I'll upload chrisrcooper's code as a patch.

brockfanning’s picture

Status: Active » Needs review
StatusFileSize
new1.02 KB

Here's a patch using the code in #1. The only change was to look for "youtube.com/" instead of "youtube", just on the off-chance a local video file has the word "youtube" in it.

diwant’s picture

Status: Needs review » Reviewed & tested by the community

I tried this patch and it worked for me. Thanks all!

mickfuzzz’s picture

Works for me too.
It's good to have a solution that works for all files and embeds.

mickfuzzz’s picture

Issue summary: View changes

Added code wrappers

mailfox’s picture

Issue summary: View changes

#1 Works for me

ErwinS’s picture

As i do not use Vimeo vids yet, it works fine for me!

martin.l’s picture

Worked for me as well. Why can this not be committed to -dev?

matt b’s picture

Using the Link field as per #3, I was getting the error
Notice: Undefined index: description in mediaelement_field_formatter_view() (line 111 of ......./sites/all/modules/mediaelement/mediaelement.module).

Line 111 is $display['settings']['description'] = $item['description']; which doesn't exist if you are using the Link module.
I've change this line to

    if (module_exists('link') && array_key_exists('url', $item)) { //Link module installed and being used
      $display['settings']['description'] = $item['title'];
    } else {
      $display['settings']['description'] = $item['description'];
    }

And no longer get the error.

matt b’s picture

I notice that I cannot go fullscreen when playing a YouTube video through MediaElement, but can if playing an uploaded video? You can play fullscreen on the MediaElement YouTube API example.

mastoll’s picture

Not working.
I followed #3's path:
"All you have to do is paste the URL of the Youtube video into the link field, and set the link field's display to Media Element Video."

I get a the black box (presumably the player) with a link that takes you to the YouTube page itself.

Equally frustrating, if I use a file field, I cannot upload a YouTube video. I receive the error, "Unable to handle the provided embed string or URL."

I realize these sound like different issues, but I'm wondering if in fact they are related. I am using the Media module. Do I need a YouTube module too? Is there a switch I need to set somewhere that makes MediaElement pay attention to YouTube URLs?

brockfanning’s picture

@mastoll: Probably a dumb question, but did you apply the patch in #4?

mastoll’s picture

@brockfanning:

I did not have Media:YouTube installed before.

Now, I have installed versions Mediaelement 7.x-1.2+2-dev, Media YouTube 7.x-2.0-rc4+14-dev, and Media 2.0-alpha3+79-dev with patch from https://drupal.org/node/2120307:

- without patch from #4, using a file field/media selector widget, MediaElement field formatter: a black box the size of the video displays with a white-text link in it to the YouTube page.

- with the patch from #4, all else the same: the video displays in the left 70% of the player box and the full-screen toggle doesn't work; it's like a player within a player but the inner player doesn't have the controls

- with patch from #4, all else the same AND the patch from https://drupal.org/node/1119570: the outer player disappears s.t. the overall dimensions of the player box equal the inner player i.e. it's too small, but the controls are there and they all work including the full-screen toggle AND thy are standard YouTube controls, not themed as Mediaelement would have them.

- removed patch from #4, keeping patch from node/1119570: no visible changes, in fact I cannot change the size of the player in Manage Display. But I do get massive Undefined Index errors in the media_youtube\themes\media_youtube.theme.inc.

adam_bear’s picture

I fixed Youtube and a few other things...

https://github.com/ablank/imediaelement.module

mtoscano’s picture

I am using adam_bear version available at https://www.drupal.org/node/1802388#comment-9768483 and it is working great. Ideally can become new recommended version after 3 years without a new release.

robbielink’s picture

adam_bear version looks good but wondering if I have to edit all posts using current version of mediaelement to use this improved version.

adam_bear’s picture

Glad y'all like it :)

The field display for each content type (Article, Basic Page, etc.) will need to be changed, but posts don't need to be converted individually. There is more detailed information on how to implement @http://ablank.github.io/imediaelement.module/.

prineshazar’s picture

@brockfanning thanks! #4 worked for me. Mediaelement version 7.x-1.2.

I also wanted both youtube links to work, the share link and the normal URI in the address bar when viewing a youtube video. The motivation behind this was to make things a little easier for my client, as they would often forget to use the 'share' link.

After aplying patch #4, i added code below:

In mediaelement.module

@@ -104,8 +104,15 @@ function mediaelement_field_formatter_view($entity_type, $entity, $field, $insta
   $path = drupal_get_path('module', 'mediaelement');
   foreach ($items as $delta => $item) {
     // Support the link field type which stores it's data in 'url'.
-    $src = ($field['type'] == 'link_field') ? $item['url'] : $item['uri'];
-    
+    if ($field['type'] == 'link_field') {
+      // If query passed as part of video url include it.
+      $src = (count($item['query']) > 0) ?
+        url($item['url'], array('query' => $item['query'])) : $item['url'];
+    }
+    else{
+      $src = $item['uri'];
+    }
+
     $settings = $display['settings'];
     $js_settings = array();
     $js_settings['opts'] = array();

This takes into account query param v, so you can add a youtbe link like: https://www.youtube.com/watch?v=t5tbOSyyxTY rather than https://youtu.be/t5tbOSyyxTY .

jnettik’s picture

Status: Reviewed & tested by the community » Closed (cannot reproduce)

Testing the current version of the plugin and the module, YouTube videos play fine. Closing.