Jump to content

Video provider switch need help


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
https://forums.phpfreaks.com/topic/286159-video-provider-switch-need-help/
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;
}
  On 2/13/2014 at 4:30 PM, Ch0cu3r said:

 

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?

  Quote

 

 

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
}

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.