afaaro Posted February 13, 2014 Share Posted February 13, 2014 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 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 13, 2014 Share Posted February 13, 2014 is there any help that when ever i post this field should switch to it's player Can you be more specific. What files should be played with what player? You tried using the HTML5 audio and video tags? Quote Link to comment Share on other sites More sharing options...
afaaro Posted February 13, 2014 Author Share Posted February 13, 2014 (edited) 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 February 13, 2014 by afaaro Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 13, 2014 Share Posted February 13, 2014 (edited) 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 February 13, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
afaaro Posted February 13, 2014 Author Share Posted February 13, 2014 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 Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 13, 2014 Share Posted February 13, 2014 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 } Quote Link to comment Share on other sites More sharing options...
Solution afaaro Posted February 13, 2014 Author Solution Share Posted February 13, 2014 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.