can i use mediaelement module for videos on youtube? (i use media module for youtube videos)
if i can, how?

Comments

mfer’s picture

Status: Active » Fixed

Not easily. This module is designed to take a file or url for a h.264 video and play it. If you can get that URL or upload the file you can play it. With YouTube this is not so easy.

shawn_smiley’s picture

Related to this question, is there a way to configure MediaElement or the Media module so that it will use the default YouTube display with YouTube Videos and use Media Element for local videos?

So far I've been able to get a site to either display YouTube videos and local videos get a download link or display local videos using MediaElement and YouTube videos get a download link within the MediaElement player.

Status: Fixed » Closed (fixed)

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

mpotter’s picture

Category: support » feature
Status: Closed (fixed) » Active

I am re-opening this as a feature request. I have a mix of video sources (via the Media module). Some are local and need the MediaElement player (such as MP3, WMV, etc). However, some are external links to YouTube. This is all via a Media field within a content type.

If I set the display of this field to be MediaElement, then YouTube videos do not show the normal embedded YouTube player. They simply show the "Download File" link. But the local files work fine.

If I set the display of this field to be Generic File then the YouTube video shows correctly with the embedded player, but of course now none of the other local files show any player.

There definitely needs to be a way to tell MediaElement to ignore a field that uses an external URI (such as YouTube) so that it does not overwrite the embedded player.

mpotter’s picture

I have a temporary "fix" for this. I'm not going to make it a real patch because this is very specific to fixing MediaElement to work with Media:YouTube and I'm sure there is a *much* better way to generalize this code.

In the mediaelement.module file, find the function "mediaelement_field_formatter_view". What we want to do is prevent the mediaelement field display from activating for youtube items. Existing code:

  static $id = 0;
  $element = array();
  $path = drupal_get_path('module', 'mediaelement');
  foreach ($items as $delta => $item) {
    $settings = $display['settings'];
...
  }
  return $element;

Add code just after the "foreach" so it looks like this:

  static $id = 0;
  $element = array();
  $path = drupal_get_path('module', 'mediaelement');
  foreach ($items as $delta => $item) {
    $scheme = file_uri_scheme($item['uri']);
    if ($scheme == 'youtube') {
      $element[$delta] = array(
        '#theme' => 'media_youtube_video',
        '#uri' => $item['uri'],
      );
    }
    else {
      $settings = $display['settings'];
...
    }
  }
  return $element;

Perhaps somebody else can improve this to handle any scheme that isn't "public" to properly fill in the correct theme function. I just hard-coded this specific case for the Media:YouTube module so that I could get my client site working. But I hope this helps somebody else dealing with this and inspires the MediaElement module developers to do a more general fix.

pbuyle’s picture

With recent version of Media, this shouldn't require change to the MediaElement module. For your file type, you can select different file formatters and sort them. The first one to return a result will then be used. If you have, or made, a Youtube formatter that only return a render element if the media (actually a File entity) is a YouTube video, give it a lighter weight and it will be used prior to MediaElement.

rob c’s picture

I think it has more to do with the player rendered (to match on the whole site). So all video's look and feel the same. (feature: player templates/themes, anyone?)

@mongolito404 nice info, but would that do what i describe? Else we'lll need to theme the youtube player with some mediaelement saus to get where i want to go for example. Or am i missing something completely?

(and shouldnt youtube be on top just like flickr vimeo etc by default? mediaelement will never have to deal with all these anyway, so why put mediaelement higher on that page you describe?) (just a thought)

BeaPower’s picture

Any updates?

citlacom’s picture

I did a similar patch to support media_vimeo and media_youtube due the conflict that happens when are installed with mediaelement. The solution was similar as #5:

  foreach ($items as $delta => $item) {
    $scheme = file_uri_scheme($item['uri']);
    if ($scheme == 'youtube') {
      $element[$delta] = array(
        '#theme' => 'media_youtube_video',
        '#uri' => $item['uri'],
      );
      foreach (array('width', 'height', 'autoplay') as $setting) {
        $element[$delta]['#' . $setting] = $display['settings'][$setting];
      }
    }
    else if ($scheme == 'vimeo') {
      $element[$delta] = array(
        '#theme' => 'media_vimeo_video',
        '#uri' => $item['uri'],
      );
      foreach (array('width', 'height', 'autoplay') as $setting) {
        $element[$delta]['#' . $setting] = $display['settings'][$setting];
      }
    }
    else {
      $settings = $display['settings'];

But this is not a clean fix and probably the hook_field_formatter_view() should be changed to hook_file_formatter_FORMATTER_view() as implemented in media_vimeo.formatters.inc of the media_vimeo module.

Letharion’s picture

Title: videos on youtube » Field formatter renders online videos, (youtube, vimeo etc) unplayable
Version: 7.x-1.0 » 7.x-1.x-dev
StatusFileSize
new4.54 KB

I have need for the same thing. Attaching #9 as a patch instead so it can be used with drush make.

Letharion’s picture

New patch for mediaelement 1.1

rwilson0429’s picture

Thanks for the patch. Tried to use the patch in #11. 'Hunk #1 Failed at 103.' Then, I tried #10, 'Hunk #1 failed at 128'.

alan d.’s picture

Status: Active » Needs review
StatusFileSize
new4.58 KB

This is a re-roll against 1.x branch

This is mostly Letharion work. Minor changes:
* The autoplay is not a setting from the formatter, but I've keep this in the properties loop with a isset() check to prevent warnings.
* Moved the $settings outside of the loop.

Related: html5 video wrappers for these fields

http://johndyer.name/html5-video-wrapper-for-youtube-and-vimeo-api-media...

Unrelated: This kinda feels functionally wrong. Shouldn't the media file define the base formatter and then call the specific media rendering handlers?

dpfitzsi’s picture

Status: Needs review » Reviewed & tested by the community

Thanks Alan D., I know this is an old issue but I found I needed to resolve this use case today. Your patch works great against the -dev branch of the module.

Can this be committed?

martin.l’s picture

Issue summary: View changes

I used this patch and it worked for me:
https://drupal.org/node/1802388

jnettik’s picture

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

Testing the current functionality of the plugin and module, YouTube links seem to play fine. Closing.