Responsive Media

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
dddave's picture

Introduction

Serving the content of a site to mobile devices is more important then ever and a lot of sites take a responsive approach, i.e. not using a dedicated mobile version of the site but instead resize and reorder the content depending on the screen-size.
Using a theme like Omega, AdaptiveTheme or Arctica (just to name a few) you can create a responsive design fairly easily. Images resize nicely thanks to html5 and the same would go for videos utilizing the "video" element.
The crux for users of the Media module and supporting module like Media_Youtube is that rich media embedded to your site usually comes in form of an iframe or other "magic" and making these embeds responsive is not trivial.

Solutions

1. CSS

http://webdesignerwall.com/tutorials/css-elastic-videos
This works well but requires some swagger for users not used to fiddle with css. Using this approach for wysiwyg-embeds might be quite hard.

2. FitVids.js

http://daverupert.com/2011/09/responsive-video-embeds-with-fitvids/
This approach works well in general and comes with a dedicated and maintained module: http://drupal.org/project/fitvids
The problem here is that setting the module up to work with Media_youtube is far from trivial as documented in issues as: Which class selector to use with embed videos from youtube
So far I couldn't get it to go completely. Not only is there the need to set the height and width to „empty“ in the manage file display screen if you are using a file-field. After that your video is responsive but somehow receives a dinky height: 150px; from somewhere when the height needs to be set to „auto“. So far I neither was able to make out where the 150 is coming from nor if I am using the fitvids module correctly. Feedback would be very welcome.
If we could document how to use this module alongside Media users could easily achieve responsive behavior without diving into files like in the css approach.

3. Media provides fluid embeds out-of-the-box

Media (or a submodule) could provide fluidity of embedded media directly without further fiddling. This is discussed in the following issues:
Add a library to handle fluid sizes for embedded media
Which was working a long time ago but currently seems broken.

Responsive Embeds
A dedicated issue in Media_yt's queue which spawned most of this post. RobW raises some very valid points:

I also noticed that there's some .js in the Youtube and Vimeo media modules meant to make videos liquid/responsive. Problems there are:
1.They're in both Vimeo and Youtube modules, so if they were called would be repeating themselves.
2.They're never called in the Vimeo module, so probably aren't that important/used/functional.
3.They're definitely loaded by default with Youtube, whether wanted or not.
I don't think that making a video responsive should be part of the basic functionality of a module like this, especially if it adds complexity, javascript, or page weight. If a user has Youtube, Vimeo, an oEmbed provider, and their own uploaded videos on a site they should be able to add responsiveness across the board with either a js plugin calling a sitewide video class, or a css solution based on repeated structure and class names. The thing they (ok, I mean I) don't want is two or more proprietary solutions overlapping and conflicting with each other.

Rich media display with and HTML5 elements.
This issue is more about correctly supporting video and audio elements. As far as I understand it embedded content wouldn't be affected by this. Am I correct?

Bottom line

I think that responsive handling of „rich“ media is an important topic. And considering the impressive adoption rate of Media I think we should provide a good solution for users not keen or able to hack a solution together. As far as I can see we either make Media work with fitvids.js and document how to correctly set this up OR we provide a solution ourselves (via media-core or a submodule).

Questions

  1. What is or should be the course of Media?
  2. What are your recipes to provide responsive media embeds?
  3. Should we use a dedicated tag on issues affecting or about responsiveness/mobile- friendliness? Which one?

A better formated and better formulated version of this post was swallowed upon preview. Sorry, but that is all I was able and willing to restore. Improvements might follow.

Results

Thanks to RobW for his awesome work making media_youtube sane and DRY. We now have working blueprint how to embed in a way that we can achieve responsive designs with reasonable effort. Using fitvids.js now is pretty easy, especially if you understand a little bit of CSS. This is definitely a big leap forward.
Thanks to Aaron Winborn for committing the patch.

Comments

DRY DRY DRY

RobW's picture

Thanks for starting this discussion, dddave.

I have some strong opinions on this.

Don't Repeat Yourself. This is absolutely #1. Modules that supply a field should not provide responsive code just for that field. That would be... MADNESS.

Instead, media modules should put effort into providing vanilla code that allows other modules, or css and js in the theme layer, to provide responsiveness. This boils down to minimizing javascript manipulation of produced html and avoiding inline style attributes (best practice anyways, right?). If all a media field provider spits out is pure, static HTML, it will be easy for module and front end developers to integrate a responsive technique of their choice.

Media Youtube is currently the biggest offender against the above points. I'm going to try to find some time soon to really dig into the code and make a few patches to adress these issues, maybe even organize a mini local code sprint here in Pittsburgh. If anyone wants to collaborate, send me a pm.

Responsive images

westis's picture

I've started to implement responsive images in the Community Media theme using the resp_img module. That works great as long as a view field or content type is using an image style directly. But I ran into problem when a view field is using a file style that in turn is using an image style that by itself should be responsive (http://drupal.org/node/1608764)

Would you say that the resp_img is a good way to go to scale and crop images to only serve the client with the largest image based on the browser size?

Sigh

dddave's picture

So responsive themes usage is constantly rising and media module an important module on a lot of sides. How the heck are people working around the existing limitations?
It seems nobody is caring or has his own private workaround.
At the moment the Media family is running into a dead end concerning responsiveness or even mobile friendliness in general.

Props to RobW for tackling Media Youtube. Looking forward to any results.

Does anybody know about plans from the big providers to give us html5 players? Soundcloud has one which works awesomely but I guess this is harder to do for videos...

Responsive MediaElement

dddave's picture

Although my main concern is about embeded third-party media I want to include a link to a related issue in the MediaElement queue. There they are working on making MediaElement responsive: http://drupal.org/node/1348816

(...) Images resize nicely

brunodbo's picture

(...) Images resize nicely thanks to html5 (...)

Just curious, could you clarify this? How does html5 improve/handle resizing of images?

Ugh

dddave's picture

Yeah, that part didn't make a lot of sense now. Seems to be one of the parts that I had problems with reconstructing when my first post went down the toilet.
I think what I wanted to stress is that modern html5 themes make it easy to provide responsive elements or make it easy to create responsiveness.
This contrasts with the embeds from third-parties which are the real problem here.

I am going to edit this when I gather my thoughts a little bit better.

Youtube patch

RobW's picture

If anyone is interested, I just posted the Media: Youtube patch I mentioned above. The parts that relate to this thread: it doesn't provide responsiveness, but instead makes it easy for site wide responsive techniques to be applied to its output. No module provided css or js manipulations, easily themable in a tpl, etc. http://drupal.org/node/1555276#comment-6156570

Everyone involved in Media that I've talked to on IRC supports the DRY, html-object based responsive ideas we've touched on here. As soon as I get the Media: Youtube patch squared away I'll write up a responsive doc/guidelines for Media provider modules and Drupal modules in general. I'll post it here for discussion and contribution.

For those who care (not a lot

dddave's picture

For those who care (not a lot I figure),
Rob provided another game changing patch for media_vimeo: http://drupal.org/node/1715438

Check it out!

I need to make my .flv videos

symphonia's picture

I need to make my .flv videos responsive, but I can't find a solution. I've also tried with fitvids.js but it didn't work for me...
Anyone can help please...?

HTML5 Video

vtitarchuk's picture

Resently I came accross Video.js that was very promising for mobile devices. I am not sure if Video player will play .flv files, but it is worth checking it out: http://videojs.com/

ServanTek
Serving with technology
http://servantek.org.ua

Thanks for starting the topic

trainingcity's picture

This is exactly the issue I am struggling with for my D7 site. I am certain this is a critical issue for sites over the next year or two as their clients migrate to mobile and their oembed videos remain too static and two large for proper viewing.

I am going to check out RobW's patches, thanks for all the effort.

Both patches are in the dev

RobW's picture

Both patches are in the dev releases of the module now. For all oembed/flash videos, see fitvids.js (which has a Drupal module) and Uncle Dave's ol' padded box css technique.

RobW++ !! Just awesome!

c8n's picture

RobW++ !! Just awesome!