0

I am storing the YouTube and video embed urls in my database. Then calling the video URL in the modal to play the video. But video keeps playing even if the modal is closed. I have tried this solutions and it works for me, but it assign the same id to every video. I mean, i have 6 different videos in my page and this solution then, play the same video in every modal. Please guide. Thanks in advance

Here is my code

if($row['link_type'] == 'yt_video'){
                                   ?>
<div class="modal" id="mod<?=$i ?>" tabindex="-1" role="dialog" aria-hidden="true">
                                        <div class="modal-dialog modal-lg" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <!--<h5 class="modal-title" id="exampleModalLabel">Add Video Url For <b><?php echo $row['title']; ?></b></h5> -->
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                                                </div>
                                            <div class="modal-body">
                                                <!-- video section strts  -->
                                                <div class="service-video-section josh-js"  data-josh-anim-name="" data-josh-duration="1500ms" data-josh-anim-delay="3.5s">
                                                    <div class="video-section-content">
                                                        <div class="video">
                                                            <?=$row['link_desc'] ?>
                                                        </div>
                                                    </div>
                                                </div>
                                                <!-- video section Ends  -->
                                            </div>
                                            </div>
                                        </div>
                                    </div>
<?php
                                       
                                   }                                   
                                    $i++;
                                    } 
                                    ?>

And here is my solution that i tried

<script language="javascript" type="text/javascript">

    $(function(){
            $('.close').click(function(){      
                    $('iframe').attr('src', $('iframe').attr('src'));
    });
            });
</script>
Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55

1 Answers1

0

Have you considered using the youtube and vimeo APIs? You will then be able to control the embeded players controls i.e. stop, play, pause etc. Like mentioned below:

Stop embedded youtube iframe?

Then when you fire the close.click function you can also stop the video.

Jake B.
  • 436
  • 3
  • 6