How to Extract Youtube Video Values from an image field

More
2 years 7 months ago - 2 years 7 months ago #80672 by iamrobert
I wanted a way to customize the output of a gallery if I load an image or a video from Youtube or Vimeo as I use plyr :

 

You should understand the raw value of a field  inside flexicontent templates concept.

To detect a video value use:

Code:
if ( $v[ 'mediaurl' ] != '' ) { }


To detect an image value use:

Code:
if ( $v[ 'mediaurl' ] == '' ) { }


as mediaurl only outputs for video.


To extract the video ID for youtube or Vimeo:


Code:
    if ( $v[ 'mediaurl' ] != '' ) {       //GET VIDEO URL       $datavideo = $v[ 'mediaurl' ];       //GET YOUTUBE ID       if ( preg_match( '/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/', $datavideo, $match ) ) {         $datavideo = $match[ 1 ];         $provider = "youtube";       }       //GET VIMEO ID       if ( preg_match( "/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/", $datavideo, $output_array ) ) {         $datavideo = $output_array[ 5 ];         $provider = "vimeo";       }       //CREATE MEDIA OBJECT          echo '<li>';       echo '<div class="plyr__video-embed">';       echo '<div data-plyr-provider="' . $provider . '" data-plyr-embed-id="' . $datavideo . '" class="js-player">';       echo '<li>';     }



Here's the complete code for either Video or Image:

gist.github.com/iamrobert/8dd0339c279bb38066e13086f6f8eaa8
Last edit: 2 years 7 months ago by iamrobert.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #80734 by micker
its specific for plyr ? because we already generate image and video in image field you have an option for this
we want to add a player  in video field, can you propose something?

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]
Last edit: 2 years 7 months ago by micker.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #80735 by iamrobert
It's Plyr.io specific. It's also useful if you need a way to extract the VIDEO ID from either Youtube or Vimeo.

For example, you have lightbox JS that needs to handle video or images you can do it that way. Or you want to use the high-resolution youtube image.

I updated the gist to show the full code that allows us to choose either image or Video.
Last edit: 2 years 7 months ago by iamrobert.

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.283 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline