JPlayer + Ajax page load

亡梦爱人 提交于 2019-12-21 23:50:40

问题


I will try to keep this short:

How would i manage to make a unique instance of jPlayer (http://jplayer.org/) "work" after an ajax page load?

My jPlayer uses the following inline javascript code:

<?
    $mp3    = get_post_meta(get_the_ID(), 'audio_mp3', TRUE);
    $ogg    = get_post_meta(get_the_ID(), 'audio_ogg', TRUE);

?>

<?php if($mp3 && $ogg) { ?>

<script type="text/javascript">
jQuery(document).ready(function($) {


        jQuery( '#jquery_jplayer_<?php the_ID(); ?>' ).jPlayer({
            ready: function() {
                jQuery(this).jPlayer('setMedia', {
                    mp3: "<?php echo ($mp3); ?>",
                    oga: "<?php echo ($ogg); ?>"
                    });
                },
            swfPath: "<?php echo get_template_directory_uri(); ?>/js/jplayer/",
            cssSelectorAncestor: "#jp_container_<?php the_ID(); ?>",
            supplied: "<?php if($mp3 != '') : ?>mp3, <?php endif; ?><?php if($ogg != '') : ?>oga, <?php endif; ?> all"
        });


});

</script>

For non unique stuff like a prettyPhoto lightbox for example i created a function (prettyPhoto(); wich i put in the callback. But i cannot seem to get this working with jplayer!

Any help would be apriciated!


回答1:


I recommend using the playlist add-on.

  1. Create an empty player instance

    var jpplaylist = new jPlayerPlaylist({
        jPlayer: "#jquery_jplayer_1",
        cssSelectorAncestor: "#jp_container_1"
        }, [], {
            swfPath: "/path/to/swf",
            supplied: "mp3",
            wmode: "window"
        });
    
  2. After your AJAX page load, use the setPlaylist function to add your tracks:

    jpplaylist.add({
        title:"Song Title",
        mp3:"http://example.com/example.mp3"
    });
    

The full playlist specs are here: http://www.jplayer.org/latest/demo-02-jPlayerPlaylist/



来源:https://stackoverflow.com/questions/12036063/jplayer-ajax-page-load

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