How to Extract Youtube Video Values from an image field

2 months 2 days ago - 2 months 2 days 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:

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


To detect an image value use:

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


as mediaurl only outputs for video.


To extract the video ID for youtube or Vimeo:


    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

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

1 month 4 weeks ago - 1 month 4 weeks 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]

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

1 month 3 weeks ago - 1 month 3 weeks 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.

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

Moderators: vistamediajoomlacornerggppdk
© 2018 Flexicontent. All Rights Reserved.