I want to display youtube video on a page, the following is my code in order to fetch youtube video URL from the database stored in mysql and then display it by iterating using while loop. However, the iframe does not display any video inside it.
<?php
if ($get_result != false) {
while ($row = mysqli_fetch_array($get_result, MYSQLI_ASSOC)) {
?>
<iframe width="560" height="315" src="<?php echo $row["url"]; ?>" frameborder="0" allowfullscreen></iframe>
<?php
}
}
?>
I have also tried using video tag inside while loop but it does not display the Youtube video inside the video player.
Please help me to solve this issue.
You can use Youtube with embed, like this:
<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php echo $row["url"]; ?>?autoplay=1&autohide=1&controls=1&showinfo=0&modestbranding=1&rel=0"></iframe>
The problem is with your URL value.Replace "watch?v=" in video url with "v/" and try again.For example I tried with
<iframe width="560" height="315"
src="https://www.youtube.com//v/txSGdNONUJE" frameborder="0" allowfullscreen></iframe>
The above code will work fine.
Related
I want to display the youtube link stored in the database and just call the link but it can't
<div class="divideo">
<iframe width="560" height="315" src="<?php echo $link; ?>" frameborder="0" allowfullscreen></iframe>
</div>
but youtube can't connect
<div class="divideo">
<iframe width="560" height="315" src="<?php echo base_url(); ?>/path/<?php echo $link ?>" frameborder="0" allowfullscreen></iframe>
</div>
You should have to give the proper path of the video link if that link is in your server if you are using an external source then use a proper link in your src tag.
I have a variable that stores an array, and in that array there is a YouTube url.
When I var dump
$node->field_video_link
It looks like the following:
array(1) { ["und"]=> array(1) { [0]=> array(5) { ["video_url"]=> string(43) "https://www.youtube.com/watch?v=SC9BgH_L29c" ["thumbnail_path"]=> string(61) "public://video_embed_field_thumbnails/youtube/SC9BgH_L29c.jpg" ["video_data"]=> string(34) "a:1:{s:7:"handler";s:7:"youtube";}" ["embed_code"]=> NULL ["description"]=> NULL } } }
Now, I want to use the video link as an iframe so that users can watch through the site and I did it like the following:
$sample1_video_link = (isset($node->field_video_link['und'])) ? file_create_url($node->field_video_link['und'][0]['video_url']) : '';
<iframe width="420" height="315"
src="<?php print $sample1_video_link; ?>">
</iframe>
When I go view the page, the video thumbnail does not appear, and instead, I see a message that says "www.youtube.com refused to establish connection"
However, if I grab a random URL from youtube, the iframe works.
The error looks like in the below image:
Anything I am possibly doing wrong?
EDITED:
I now use echo instead of print and when I reload the page, still the same error.
<iframe src="<?php echo $sample1_video_link; ?>"></iframe>
When I inspect the page, I see the following:
<iframe src="https://www.youtube.com/watch?v=SC9BgH_L29c"></iframe>
Which is apparently the same value being stored in the array.
use echo instead of print:
src="<?php echo $sample1_video_link; ?>">
also youtube generates embedding url (share below the video) use that one instead they also generate an example iframe structure :
<iframe width="560" height="315" src="https://www.youtube.com/embed/SC9BgH_L29c" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
going by your code you can jsut add the video id after "https://www.youtube.com/embed/"
or
src="<?php echo str_replace("https://www.youtube.com/watch?v=","https://www.youtube.com/embed/",$sample1_video_link; ?>">
Hi I am trying to display an iframe video from YouTube on a page. I get a 404 error on blank block when I run the page. What could possibly be wrong?
My code is:
<iframe width="854" height="480" src="{{ $vid->videoURL . '&output=embed' }}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
Change your url from https://www.youtube.com/watch?v=8nbsSkwSbb0&output=embed to https://www.youtube.com/embed/8nbsSkwSbb0. The /embed endpoint allows outside requests, while the /watch does not. I think, you can create an accessor method in your Video model like this:
public function getSrcAttribute()
{
// $this->videoUrl: https://www.youtube.com/watch?v=8nbsSkwSbb0
parse_str(parse_url($this->videoURL)['query'], $output);
return 'https://www.youtube.com/embed/' . $output['v'];
}
Then use it like:
<iframe
src="{{ $vid->src }}"
width="854"
height="480"
frameborder="0"
allow="autoplay; encrypted-media"
allowfullscreen></iframe>
I have create a form, after details have been submitted I am trying to open an Iframe for the response. But I keep receiving an error in the line in bold.
This is my code:
// this code is within my php code
if($result){
**echo <li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>**
}
else{
echo"ERROR"
}
datasave.php ==> This is the code in this file
<?php
echo Your details have been sent successfully!;
?>
Either:
Leave PHP mode if you want to go into output mode. You can't just put raw HTML where PHP is expected.
if($result){
?>
<li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>
<?php
}
or
Put delimiters (" or ' usually) around your PHP strings.
if($result){
echo '<li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>';
}
Just replace your this line
**echo <li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>**
with this one
echo '<li><iframe width="420" height="315" src="datasave.php" frameborder="0"></iframe></li>';
How can I get the video ID for youtube and vimeo videos embed code? A youtube video embed code looks like this:
<iframe width="560" height="315" src="http://www.youtube.com/embed/dbPmWbqAJPs" frameborder="0" allowfullscreen></iframe>
where the ID in this is dbPmWbqAJPs.
A vimeo embed code looks like this:
<iframe src="http://player.vimeo.com/video/62468031?color=00ff00" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
where the ID in this example is 62468031.
I don't want to replace those exact ids, but rather have a pregmatch/pregreplace that finds the id in any embed of vimeo and of youtube.
try this
vimeo
$string='<iframe src="http://player.vimeo.com/video/62468031?color=00ff00" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
preg_match_all( '~http://player.vimeo.com/video/(.*?)\?~si',$string,$M);
echo ($M[1][0]);
youtube :
$string='<iframe width="560" height="315" src="http://www.youtube.com/embed/dbPmWbqAJPs" frameborder="0" allowfullscreen></iframe>';
preg_match_all( '~http://www.youtube.com/embed/(.*?)\"~si',$string,$M);
echo ($M[1][0]);
Try below code for php, it works without pregmatch
i.e. :
http://vimeo.com/22222222
http://player.vimeo.com/video/22222222
http://vimeo.com/channels/staffpicks/22222222
http://vimeo.com/groups/groupsname/22222222
PHP Code :
$vimeoUrl = 'http://vimeo.com/channels/channelsName/22222222';
$fetchVimeoIdArr = explode('/', $vimeoUrl);
$idCounter = count($fetchVimeoIdArr) - 1;
$vimeoId = $fetchVimeoIdArr[$idCounter];