Jump to content

Video provider switch need help


afaaro
Go to solution Solved by afaaro,

Recommended Posts

Hello everyone


 


I have in my table  post_url and i use for  [Audio link, youtube link, etc.....] is there any help that when ever i post this field should switch to it's player. I found this code from somewhere but i don't know how


 


if($player_file != ''){

    if($player_dir)

        $folder = '/'.$player_dir;

    $file = Folder/player/".$player_file;

    if(file_exists($file))

        include_once($file);

}

 


 


Thank you 


 

Link to comment
Share on other sites

Thank you for the reply Ch0cu3r

 

I have got a text field  for post_url->   I need to insert a URL from youtube link, vimeo link, audio link and etc....

 

how does it recognise which player for the post_url text field.

Edited by afaaro
Link to comment
Share on other sites

You'd have to analyse the domain of the url the user posts, so if the url contains youtube.com then it's a youtube video, if it contains vimeo.com the it is a vimeo video etc. Once you have found out the video source you can then inject their video url into the embedded player code, for youtube, vimeo etc.

 

Example code

$videoSource = parse_url($videoUrl, PHP_URL_HOST); // get the domain from the video url

// display embedded video based on domain
switch($videoSource) {
   case 'youtu.be':
   case 'youtube.com':
      // embedded player code for youtube video
   break;

   case 'vimeo.com':
      // embedded player code for vimeo video
   break;
}
Edited by Ch0cu3r
Link to comment
Share on other sites

 

You'd have to analyse the domain of the url the user posts, so if the url contains youtube.com then it's a youtube video, if it contains vimeo.com the it is a vimeo video etc. Once you have found out the video source you can then inject their video url into the embedded player code, for youtube, vimeo etc.

 

Example code

$videoSource = parse_url($videoUrl, PHP_URL_HOST); // get the domain from the video url

// display embedded video based on domain
switch($videoSource) {
   case 'youtu.be':
   case 'youtube.com':
      // embedded player code for youtube video
   break;

   case 'vimeo.com':
      // embedded player code for vimeo video
   break;
}

 

WooooW  that is really promising. it worked. Thank you Ch0cu3r

 

One more question how can i include an audio link from my website?

Link to comment
Share on other sites

 

 

One more question how can i include an audio link from my website?

The problem is how do you know it is going to be an audio file? You might want to add a radio button which the user chooses video, or audio. When the form is posted you'd check what type of media they have linked to. When they select video, you'd run the code for embedding the video player. For audio you'd use their url in the html5 audio tag.

// form
<form>
...
<p>Media Type: <input type="radio" name="type" value="Audio" /> Audio OR <input type="radio" name="type" value="video" /> Video?</p>
<p>Link: <input type="text" name="media-link" /></p>
...
</form>

// php
<?php
if($_POST['type'] == 'audio')
{
    // code for html audio tag
}
else
{
    // code for embedded video player
}
Link to comment
Share on other sites

  • Solution

Yes Its working perfect; Thank you for your great time I really appreciate thank you again.

function videoPlayer($vid){
    $videoSource = parse_url($vid, PHP_URL_HOST); // get the domain from the video url

    $return = "";
    switch($videoSource) {
        case 'youtu.be':
        case 'youtube.com':
            $return = $vid;
        break;
        case 'vimeo.com':
            $return = $vid;
        break;
        case 'blip.tv':
            $return = $vid;
        break;
    }
    return $return;
}

echo videoPlayer($vid);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.