Video in jQuery and Fancybox (Local video file mp4 Instead of Youtube)

人走茶凉 提交于 2019-12-09 04:13:37

问题


I am successfully running a Youtube Video in Jquery FencyBox. But, I am unable to run a local MP4 Video File in Jquery FencyBox (this file exists in a folder)

Please tell me how can i run a local video file in JQUERY FENCYBOX (same as i am running a youtube video in FencyBox).

Following is the code i am using:

1). I AM USING THESE FILES(PLUGINS) :

jquery.fancybox-1.3.4.js AND jquery.fancybox-1.3.4.css

2). Successfully Playing video from Youtube in Fancy Box:

<div class="main">
    <h1>VIDEO Playing From YOUTUBE</h1>
    <p><a href="http://www.youtube.com/embed/WAZ5SmJd1To" class="youtube iframe">Watch this amazing YouTube video</a></p>
</div>

3). Now I am unable to play Local Video File MP4 in Fancy Box:

<div class="main">   
    <h1>Local Video File Playing</h1>
    <p><a href="example/video.mp4" class="youtube iframe" > My Local Video in Example Folder</a></p>         
</div>

Please suggest/guide/help.


回答1:


The issue is that most media objects require a player to run, either a (self-hosted) third-party software or a browser's plugin/extension, normally quicktime for MP4 videos.

In the case of youtube, they provide already with an embedded player so you don't have to worry about that but in the case of your local video(s), you still need to use an external player, let's say jwplayer (or any other of your preference.) Notice that fancybox doesn't include any video player.

So I would use the following html to link each video

<a class="fancybox" data-type="iframe" href="http://www.youtube.com/embed/WAZ5SmJd1To?autoplay=1" title="youtube">open youtube (embed mode)</a><br />
<a class="fancybox" data-type="swf" href="pathToPlayer/jwplayer.swf?file=pathToVideo/video.mp4&autostart=true" title="local video mp4">open local video</a>

Notice that I added a (HTML5) data-type attribute to indicate the type of content fancybox (v1.3.4) should handle. I used swf for your local video since I will be using a swf player (jwplayer.swf) regardless I am playing a mp4 video.

then you could use this script for any of them :

jQuery(document).ready(function($){
    $(".fancybox").on("click", function(){
        $.fancybox({
          href: this.href,
          type: $(this).data("type")
        }); // fancybox
        return false   
    }); // on
}); // ready

You can see a demo here http://www.picssel.com/playground/jquery/localVideojwPlayer_02oct13.html

NOTE: .on() requires jQuery v1.7+ but fancybox doesn't work with jQuery v1.9+, see this for further information. You could use jQuery v1.8.3 or apply the patch as in the referred post.

LAST COMMENT: this may not work in mobile devices. You may rather prefer to use a different player like mediaelements for cross-browser/cross-platform compatibility instead (or get jwplayer v6.x with legacy browsers fallback option)




回答2:


This code helps you to run the local video file, make sure you've your .mp4 video file in your solution or else you can link the youtube video with anchor tag.

<head>
<script src="/fancybox/jquery.fancybox.js" type="text/javascript"></script>
<link href="/fancybox/jquery.fancybox.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $('#video a').fancybox({
                width: 640,
                height: 400,
                type: 'iframe'
            });
        });
    </script>
 </head>

<body>
<div id="video">
  <a href="new_video.mp4"><img src="/images/video_coverpage.jpg" alt="" /></a>       
</div>
</body> 



回答3:


Jinal answer with working example.

<head>
<script src="/fancybox/jquery.fancybox.js" type="text/javascript"></script>
<link href="/fancybox/jquery.fancybox.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $('#video a').fancybox({
                width: 640,
                height: 400,
                type: 'iframe'
            });
        });
    </script>
 </head>

<body>
<div id="video">
  <a href="http://media.gettyimages.com/videos/giant-manta-rays-video-id618487251">Click Here</a>       
</div>
</body> 


来源:https://stackoverflow.com/questions/19134625/video-in-jquery-and-fancybox-local-video-file-mp4-instead-of-youtube

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!