Textpattern tips, tutorials and code snippets

Pick the right video embedding plugin

Ok, the last Textpattern tip about article video embedding is from 2009 and mentions a few outdated plugins… Fortunately if you are a @Textpattern follower, you know that new tools were released since this publication. Let’s introduce them to new users.

You can find the current plugin list allowing video embedding on the awesome-textpattern repo; here they are:

Now when comes the time to pick one of them some differences are quite obvious, but others are more subtle.

json request vs built-in embedding code

First, I would like to differentiate between arc_vimeo, arc_youtube and oui_player from oui_embed.

oui_embed is a plugin using Embed, a PHP library by Oscar Otero, to embed any information from an external webpage from its URL. While it is powerful, it currently needs this library to be manually included in your textpattern/vendors folder to work. It also differs from the three other plugins by using the oembed format — for vids at least — to collect data, doing it slower at first load as an external request is needed to get the embbedding code.

On the other hand, arc_vimeo, arc_youtube and oui_player have no dependency and build tidy embbedding codes on their own from a video URL or ID. arc_vimeo and arc_youtube are limited to one provider and oui_player, which is easily extendable and is also able to embed music, supports a growing list of ten providers which can be modified via MassPlugCompiler to lighten the code by excluding unused services.

Players parameters made easy

arc_vimeo, arc_youtube and oui_player are also great for one thing: easily manage players parameters. In arc_vimeo, arc_youtube, parameters can be set via their tag attributes, which oui_player also allows, even if with this plugin it is recommended to use some easy to manage plugin preferences to avoid the use of too many attributes and easily keep a visual consistency between players.

Conditional embedding

Another advantage of using one of the three previously mentioned plugins is to be able to check defined URL schemes and conditionally change the embedding depending of the result of this test. Thus, arc_vimeo and arc_youtube are able to recognize Vimeo and Youtube URL’s and oui_player is able to check URL’s against all included providers, or a defined one.

For example:

<txp:arc_if_vimeo video="https://vimeo.com/155020267">
   <txp:arc_vimeo video="https://vimeo.com/155020267" />
<txp:else />
   Something else…
</txp:arc_if_vimeo>

With oui_player, the tested URL also becomes the default item to play, avoiding to repeat it in a conditional tag context.

<txp:oui_if_player play="https://vimeo.com/155020267"> // or <txp:oui_if_player play="https://vimeo.com/155020267" provider="vimeo">
   <txp:oui_player />
<txp:else />
   Something else…
</txp:oui_if_player>

oui_embed does not provide this feature and you would need to add some custom code to be able to achieve it.

Conclusion

While oui_embed can be used to embed videos, other dedicated plugins like arc_vimeo, arc_youtube and oui_player are quite light and faster to embed. They also provide more user friendly features to configure players, conditional embedding and may easily be extended using a custom field, which could really facilitate an author’s work.

For Vimeo or Youtube videos only, drmonkeyninja’s dedicated plugins are efficient and light but if you need a more flexible solution, including support for more providers and players parameters as prefs, oui_player is your friend!